diff dwtx/jface/text/rules/FastPartitioner.d @ 162:1a5b8f8129df

...
author Frank Benoit <benoit@tionex.de>
date Mon, 08 Sep 2008 00:51:37 +0200
parents 3678e4f1a766
children eb98a5cbfd78
line wrap: on
line diff
--- a/dwtx/jface/text/rules/FastPartitioner.d	Wed Aug 27 14:49:30 2008 +0200
+++ b/dwtx/jface/text/rules/FastPartitioner.d	Mon Sep 08 00:51:37 2008 +0200
@@ -37,12 +37,9 @@
 import dwtx.jface.text.rules.BufferedRuleBasedScanner; // packageimport
 import dwtx.jface.text.rules.IWhitespaceDetector; // packageimport
 
-
 import dwt.dwthelper.utils;
-
-
 import dwtx.dwtxhelper.Collection;
-
+import tango.text.convert.Format;
 
 import dwtx.core.runtime.Assert;
 import dwtx.core.runtime.Platform;
@@ -124,7 +121,19 @@
      */
     private Position[] fCachedPositions= null;
     /** Debug option for cache consistency checking. */
-    private static const bool CHECK_CACHE_CONSISTENCY= "true".equalsIgnoreCase(Platform.getDebugOption("dwtx.jface.text/debug/FastPartitioner/PositionCache"));  //$NON-NLS-1$//$NON-NLS-2$;
+    private static bool CHECK_CACHE_CONSISTENCY_;
+    private static bool CHECK_CACHE_CONSISTENCY_init;
+    private static bool CHECK_CACHE_CONSISTENCY(){
+        if( !CHECK_CACHE_CONSISTENCY_init ){
+            synchronized(FastPartitioner.classinfo ){
+                if( !CHECK_CACHE_CONSISTENCY_init ){
+                    CHECK_CACHE_CONSISTENCY_init = true;
+                    CHECK_CACHE_CONSISTENCY_ = "true".equalsIgnoreCase(Platform.getDebugOption("dwtx.jface.text/debug/FastPartitioner/PositionCache"));  //$NON-NLS-1$//$NON-NLS-2$;
+                }
+            }
+        }
+        return CHECK_CACHE_CONSISTENCY_;
+    }
 
     /**
      * Creates a new partitioner that uses the given scanner and may return
@@ -136,7 +145,7 @@
     public this(IPartitionTokenScanner scanner, String[] legalContentTypes) {
         fScanner= scanner;
         fLegalContentTypes= TextUtilities.copy(legalContentTypes);
-        fPositionCategory= CONTENT_TYPES_CATEGORY + toHash();
+        fPositionCategory= CONTENT_TYPES_CATEGORY ~ Integer.toString(toHash());
         fPositionUpdater= new DefaultPositionUpdater(fPositionCategory);
     }
 
@@ -161,7 +170,7 @@
      * </p>
      */
     public void connect(IDocument document, bool delayInitialization) {
-        Assert.isNotNull(document);
+        Assert.isNotNull(cast(Object)document);
         Assert.isTrue(!document.containsPositionCategory(fPositionCategory));
 
         fDocument= document;
@@ -594,8 +603,8 @@
      */
     protected String getTokenContentType(IToken token) {
         Object data= token.getData();
-        if ( cast(String)data )
-            return cast(String) data;
+        if ( auto str = cast(ArrayWrapperString)data )
+            return str.array;
         return null;
     }
 
@@ -701,9 +710,7 @@
             throw ex;
         }
 
-        TypedRegion[] result= new TypedRegion[list.size()];
-        list.toArray(result);
-        return result;
+        return arraycast!(ITypedRegion)(list.toArray());
     }
 
     /**
@@ -828,13 +835,13 @@
             Position[] positions= fDocument.getPositions(fPositionCategory);
             int len= Math.min(positions.length, fCachedPositions.length);
             for (int i= 0; i < len; i++) {
-                if (!positions[i].equals(fCachedPositions[i]))
-                    System.err.println("FastPartitioner.getPositions(): cached position is not up to date: from document: " + toString(positions[i]) + " in cache: " + toString(fCachedPositions[i])); //$NON-NLS-1$ //$NON-NLS-2$
+                if (!positions[i].opEquals(fCachedPositions[i]))
+                    System.err.println(Format("FastPartitioner.getPositions(): cached position is not up to date: from document: {} in cache: {}", toString(positions[i]), toString(fCachedPositions[i]))); //$NON-NLS-1$ //$NON-NLS-2$
             }
             for (int i= len; i < positions.length; i++)
-                System.err.println("FastPartitioner.getPositions(): new position in document: " + toString(positions[i])); //$NON-NLS-1$
+                System.err.println(Format("FastPartitioner.getPositions(): new position in document: {}", toString(positions[i]))); //$NON-NLS-1$
             for (int i= len; i < fCachedPositions.length; i++)
-                System.err.println("FastPartitioner.getPositions(): stale position in cache: " + toString(fCachedPositions[i])); //$NON-NLS-1$
+                System.err.println(Format("FastPartitioner.getPositions(): stale position in cache: {}", toString(fCachedPositions[i]))); //$NON-NLS-1$
         }
         return fCachedPositions;
     }
@@ -846,6 +853,6 @@
      * @return a formatted string
      */
     private override String toString(Position position) {
-        return "P[" + position.getOffset() + "+" + position.getLength() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        return Format("P[{}+{}]", position.getOffset(), position.getLength() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
     }
 }