2006-12-30 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Sat, 30 Dec 2006 16:07:56 +0000 (16:07 -0000)
committerMarek Safar <marek.safar@gmail.com>
Sat, 30 Dec 2006 16:07:56 +0000 (16:07 -0000)
* cs-tokenizer.cs (PreProcessDefinition, handle_preprocessing_directive):
Made white spaces array static.

* ecore.cs (RemoveGenericArity): Optimized.

* flowanalysis.cs (MyBitVector.Or, MyBitVector.And): Optimized (up to
10 times faster).
(MyBitVector.initialize_vector): Simplified.

svn path=/trunk/mcs/; revision=70259

mcs/mcs/ChangeLog
mcs/mcs/cs-tokenizer.cs
mcs/mcs/ecore.cs
mcs/mcs/flowanalysis.cs

index 1b8745988e47248bc27182ac7815c1dd32891695..5fedbe08fef232e09f2a3aa5b02f31ff0825b5ed 100644 (file)
@@ -1,3 +1,14 @@
+2006-12-30  Marek Safar  <marek.safar@gmail.com>
+
+       * cs-tokenizer.cs (PreProcessDefinition, handle_preprocessing_directive):
+       Made white spaces array static.
+
+       * ecore.cs (RemoveGenericArity): Optimized.
+
+       * flowanalysis.cs (MyBitVector.Or, MyBitVector.And): Optimized (up to
+       10 times faster).
+       (MyBitVector.initialize_vector): Simplified.
+
 2006-12-22  Miguel de Icaza  <miguel@novell.com>
 
        * ecore.cs: Am not entirely happy with this hack, but it seems to
index 442c3c45a6ca479d80bcedd9079f489929e7ca3f..5751834068bee5af85065143c61bd0380befec68 100644 (file)
@@ -73,6 +73,7 @@ namespace Mono.CSharp
                bool any_token_seen = false;
 
                static Hashtable tokenValues;
+               static readonly char[] simple_whitespaces = new char[] { ' ', '\t' };
 
                private static Hashtable TokenValueName
                {
@@ -1583,8 +1584,7 @@ namespace Mono.CSharp
                                return;
                        }
 
-                       char[] whitespace = { ' ', '\t' };
-                       if (arg.IndexOfAny (whitespace) != -1){
+                       if (arg.IndexOfAny (simple_whitespaces) != -1){
                                Error_EndLineExpected ();
                                return;
                        }
@@ -1892,7 +1892,7 @@ namespace Mono.CSharp
                        // Eat any trailing whitespaces and single-line comments
                        if (arg.IndexOf ("//") != -1)
                                arg = arg.Substring (0, arg.IndexOf ("//"));
-                       arg = arg.Trim (' ', '\t');
+                       arg = arg.Trim (simple_whitespaces);
 
                        //
                        // The first group of pre-processing instructions is always processed
index 890b8c73d2a71a600d6c304fabcef4ca1035f4d9..7f344a75561b113ddf616792ff52fa9ab96669d0 100644 (file)
@@ -1921,14 +1921,19 @@ namespace Mono.CSharp {
                public static string RemoveGenericArity (string name)
                {
                        int start = 0;
-                       StringBuilder sb = new StringBuilder ();
-                       while (start < name.Length) {
+                       StringBuilder sb = null;
+                       do {
                                int pos = name.IndexOf ('`', start);
                                if (pos < 0) {
+                                       if (start == 0)
+                                               return name;
+
                                        sb.Append (name.Substring (start));
                                        break;
                                }
 
+                               if (sb == null)
+                                       sb = new StringBuilder ();
                                sb.Append (name.Substring (start, pos-start));
 
                                pos++;
@@ -1936,7 +1941,7 @@ namespace Mono.CSharp {
                                        pos++;
 
                                start = pos;
-                       }
+                       } while (start < name.Length);
 
                        return sb.ToString ();
                }
index 4213bc0c49da8e5b3ee889c930d38bfb7220f339..854361292d7c5388892b538282dc3e360400ec4c 100644 (file)
@@ -1765,18 +1765,18 @@ namespace Mono.CSharp
 
                MyBitVector ()
                {
-                       vector = null;
                        shared = new BitArray (0, false);
-                       Count = 0;
                }
 
                public MyBitVector (MyBitVector InheritsFrom, int Count)
                {
-                       vector = null;
-                       shared = InheritsFrom == null ? null : InheritsFrom.Shared;
+                       if (InheritsFrom != null)
+                               shared = InheritsFrom.Shared;
+
                        this.Count = Count;
                }
 
+               //FIXME: This property is `dirty', reading changes internal status
                BitArray Shared {
                        get {
                                if (shared == null) {
@@ -1820,28 +1820,83 @@ namespace Mono.CSharp
                // </summary>
                private MyBitVector Or (MyBitVector new_vector)
                {
+                       if (Count == 0 || new_vector.Count == 0)
+                               return this;
+
+                       // Try to avoid using the indexer as it is very slow way
+                       if (new_vector.vector != null) {
+                               // TODO: Implement this correctly
+                               //if (vector == null) {
+                               //      vector = new BitArray (new_vector.vector);
+                               //      vector.Length = Count;
+                               //      return this;
+                               //}
+
+                               if (vector != null && vector.Count == new_vector.vector.Count) {
+                                       vector.Or (new_vector.vector);
+                                       return this;
+                               }
+                       } else if (new_vector.shared != null) {
+                               if (shared == null)
+                                       return this;
+
+                               if (shared.Count == new_vector.shared.Count) {
+                                       shared.Or (new_vector.shared);
+                                       return this;
+                               }
+                       }
+
                        int min = new_vector.Count;
                        if (Count < min)
                                min = Count;
 
-                       for (int i = 0; i < min; i++)
-                               this [i] |= new_vector [i];
+                       for (int i = 0; i < min; i++) {
+                               bool b = new_vector [i];
+                               if (b)
+                                       this [i] |= b;
+                       }
 
                        return this;
                }
 
                // <summary>
-               //   Perfonrms an `and' operation on the bit vector.  The `new_vector' may have
+               //   Performs an `and' operation on the bit vector.  The `new_vector' may have
                //   a different size than the current one.
                // </summary>
                private MyBitVector And (MyBitVector new_vector)
                {
+                       // Try to avoid using the indexer as it is very slow
+                       if (new_vector.vector != null) {
+                               if (vector == null)
+                                       return this;
+
+                               if (vector.Count == new_vector.vector.Count) {
+                                       vector.And (new_vector.vector);
+                                       return this;
+                               }
+                       }
+                       else if (new_vector.shared != null) {
+                               if (shared == null)
+                                       return this;
+
+                               if (shared.Count == new_vector.shared.Count) {
+                                       vector = new BitArray (shared).And (new_vector.shared);
+                                       if (Count != vector.Count)
+                                               vector.Length = Count;
+                                       shared = null;
+                                       return this;
+                               }
+                       }
+
                        int min = new_vector.Count;
                        if (Count < min)
                                min = Count;
 
-                       for (int i = 0; i < min; i++)
-                               this [i] &= new_vector [i];
+                       for (int i = 0; i < min; i++) {
+                               bool b = new_vector [i];
+                               if (!b)
+                                       this [i] &= b;
+                       }
 
                        for (int i = min; i < Count; i++)
                                this [i] = false;
@@ -1851,8 +1906,8 @@ namespace Mono.CSharp
 
                public static MyBitVector operator & (MyBitVector a, MyBitVector b)
                {
-                       if (a == null && b == null)
-                               return null;
+                       if (a == b)
+                               return a;
                        if (a == null)
                                return b.Clone ();
                        if (b == null)
@@ -1865,8 +1920,8 @@ namespace Mono.CSharp
 
                public static MyBitVector operator | (MyBitVector a, MyBitVector b)
                {
-                       if (a == null && b == null)
-                               return null;
+                       if (a == b)
+                               return a;
                        if (a == null)
                                return new MyBitVector (null, b.Count);
                        if (b == null)
@@ -1898,15 +1953,9 @@ namespace Mono.CSharp
                                return;
                        }
 
-                       vector = new BitArray (Count, false);
-
-                       int min = shared.Count;
-                       if (min > Count)
-                               min = Count;
-
-                       for (int i = 0; i < min; i++)
-                               vector [i] = shared [i];
-
+                       vector = new BitArray (shared);
+                       if (Count != vector.Count)
+                               vector.Length = Count;
                        shared = null;
                }