Maintain only single version of ordinal string comparers
authorMarek Safar <marek.safar@gmail.com>
Sat, 2 Mar 2013 21:24:26 +0000 (22:24 +0100)
committerMarek Safar <marek.safar@gmail.com>
Sat, 2 Mar 2013 21:24:26 +0000 (22:24 +0100)
mcs/class/corlib/Mono.Globalization.Unicode/SimpleCollator.cs
mcs/class/corlib/System.Globalization/CompareInfo.cs

index 65228b4da62be90dd0846843c52cd90bd3cac62d..68ec0b5c1db9b213f7f714ad185aa4b01fd3715c 100644 (file)
@@ -86,7 +86,7 @@ namespace Mono.Globalization.Unicode
 
                unsafe internal struct Context
                {
-                       public Context (CompareOptions opt, byte* alwaysMatchFlags, byte* neverMatchFlags, byte* buffer1, byte* buffer2, byte* prev1, bool quickCheckPossible)
+                       public Context (CompareOptions opt, byte* alwaysMatchFlags, byte* neverMatchFlags, byte* buffer1, byte* buffer2, byte* prev1/*, bool quickCheckPossible*/)
                        {
                                Option = opt;
                                AlwaysMatchFlags = alwaysMatchFlags;
@@ -95,7 +95,7 @@ namespace Mono.Globalization.Unicode
                                Buffer2 = buffer2;
                                PrevSortKey = prev1;
                                PrevCode = -1;
-                               QuickCheckPossible = quickCheckPossible;
+//                             QuickCheckPossible = quickCheckPossible;
                        }
 
                        public readonly CompareOptions Option;
@@ -105,7 +105,7 @@ namespace Mono.Globalization.Unicode
                        public byte* Buffer2;
                        public int PrevCode;
                        public byte* PrevSortKey;
-                       public readonly bool QuickCheckPossible;
+//                     public readonly bool QuickCheckPossible;
 
                        public void ClearPrevInfo ()
                        {
@@ -542,7 +542,7 @@ Console.WriteLine (" -> '{0}'", c.Replacement);
                {
                        byte* prevbuf = stackalloc byte [4];
                        ClearBuffer (prevbuf, 4);
-                       Context ctx = new Context (opt, null, null, null, null, prevbuf, false);
+                       Context ctx = new Context (opt, null, null, null, null, prevbuf);
 
                        for (int n = start; n < end; n++) {
                                int i = s [n];
@@ -684,14 +684,9 @@ Console.WriteLine (" -> '{0}'", c.Replacement);
 
                public int Compare (string s1, string s2)
                {
-                       return Compare (s1, s2, CompareOptions.None);
+                       return Compare (s1, 0, s1.Length, s2, 0, s2.Length, CompareOptions.None);
                }
-
-               public int Compare (string s1, string s2, CompareOptions options)
-               {
-                       return Compare (s1, 0, s1.Length, s2, 0, s2.Length, options);
-               }
-
+/*
                private int CompareOrdinal (string s1, int idx1, int len1,
                        string s2, int idx2, int len2)
                {
@@ -758,19 +753,10 @@ Console.WriteLine (" -> '{0}'", c.Replacement);
                        return len1 == len2 ? 0 :
                                len1 == min ? - 1 : 1;
                }
-
-               public unsafe int Compare (string s1, int idx1, int len1,
+*/
+               internal unsafe int Compare (string s1, int idx1, int len1,
                        string s2, int idx2, int len2, CompareOptions options)
                {
-                       // quick equality check
-                       if (idx1 == idx2 && len1 == len2 &&
-                               Object.ReferenceEquals (s1, s2))
-                               return 0;
-                       if (options == CompareOptions.Ordinal)
-                               return CompareOrdinal (s1, idx1, len1, s2, idx2, len2);
-                       if (options == CompareOptions.OrdinalIgnoreCase)
-                               return CompareOrdinalIgnoreCase (s1, idx1, len1, s2, idx2, len2);
-
 #if false // stable easy version, depends on GetSortKey().
                        SortKey sk1 = GetSortKey (s1, idx1, len1, options);
                        SortKey sk2 = GetSortKey (s2, idx2, len2, options);
@@ -786,8 +772,8 @@ Console.WriteLine (" -> '{0}'", c.Replacement);
                        byte* sk2 = stackalloc byte [4];
                        ClearBuffer (sk1, 4);
                        ClearBuffer (sk2, 4);
-                       Context ctx = new Context (options, null, null, sk1, sk2, null,
-                               QuickCheckPossible (s1, idx1, idx1 + len1, s2, idx2, idx2 + len2));
+                       Context ctx = new Context (options, null, null, sk1, sk2, null);
+                       //      QuickCheckPossible (s1, idx1, idx1 + len1, s2, idx2, idx2 + len2));
 
                        bool dummy, dummy2;
                        int ret = CompareInternal (s1, idx1, len1, s2, idx2, len2, out dummy, out dummy2, true, false, ref ctx);
@@ -801,6 +787,7 @@ Console.WriteLine (" -> '{0}'", c.Replacement);
                                buffer [i] = 0;
                }
 
+/*
                bool QuickCheckPossible (string s1, int idx1, int end1,
                        string s2, int idx2, int end2)
                {
@@ -821,6 +808,7 @@ Console.WriteLine (" -> '{0}'", c.Replacement);
                        return true;
 #endif
                }
+*/
 
                unsafe int CompareInternal (string s1, int idx1, int len1, string s2,
                        int idx2, int len2,
@@ -837,8 +825,8 @@ Console.WriteLine (" -> '{0}'", c.Replacement);
                        sourceConsumed = false;
                        PreviousInfo prev2 = new PreviousInfo (false);
 
-                       if (opt == CompareOptions.None && ctx.QuickCheckPossible)
-                               return CompareQuick (s1, idx1, len1, s2, idx2, len2, out sourceConsumed, out targetConsumed, immediateBreakup);
+//                     if (opt == CompareOptions.None && ctx.QuickCheckPossible)
+//                             return CompareQuick (s1, idx1, len1, s2, idx2, len2, out sourceConsumed, out targetConsumed, immediateBreakup);
 
                        // It holds final result that comes from the comparison
                        // at level 2 or lower. Even if Compare() found the
@@ -1275,8 +1263,8 @@ Console.WriteLine (" -> '{0}'", c.Replacement);
                        byte* sk2 = stackalloc byte [4];
                        ClearBuffer (sk1, 4);
                        ClearBuffer (sk2, 4);
-                       Context ctx = new Context (opt, null, null, sk1, sk2, null,
-                               QuickCheckPossible (s, start, start + length, target, 0, target.Length));
+                       Context ctx = new Context (opt, null, null, sk1, sk2, null); 
+                               //QuickCheckPossible (s, start, start + length, target, 0, target.Length));
                        return IsPrefix (s, target, start, length, true, ref ctx);
                }
 
@@ -1484,7 +1472,7 @@ Console.WriteLine ("==== {0} {1} {2} {3} {4} {5} {6} {7} {8}", s, si, send, leng
                        ClearBuffer (targetSortKey, 4);
                        ClearBuffer (sk1, 4);
                        ClearBuffer (sk2, 4);
-                       Context ctx = new Context (opt, alwaysMatchFlags, neverMatchFlags, sk1, sk2, null, false);
+                       Context ctx = new Context (opt, alwaysMatchFlags, neverMatchFlags, sk1, sk2, null);
 
                        return IndexOf (s, target, start, length,
                                targetSortKey, ref ctx);
@@ -1562,7 +1550,7 @@ Console.WriteLine ("==== {0} {1} {2} {3} {4} {5} {6} {7} {8}", s, si, send, leng
                        ClearBuffer (targetSortKey, 4);
                        ClearBuffer (sk1, 4);
                        ClearBuffer (sk2, 4);
-                       Context ctx = new Context (opt, alwaysMatchFlags, neverMatchFlags, sk1, sk2, null, false);
+                       Context ctx = new Context (opt, alwaysMatchFlags, neverMatchFlags, sk1, sk2, null);
 
                        // If target is contraction, then use string search.
                        Contraction ct = GetContraction (target);
@@ -1719,7 +1707,7 @@ Console.WriteLine ("==== {0} {1} {2} {3} {4} {5} {6} {7} {8}", s, si, send, leng
                        ClearBuffer (sk1, 4);
                        ClearBuffer (sk2, 4);
                        // For some unknown reason CompareQuick() does not work fine w/ LastIndexOf().
-                       Context ctx = new Context (opt, alwaysMatchFlags, neverMatchFlags, sk1, sk2, null, false);
+                       Context ctx = new Context (opt, alwaysMatchFlags, neverMatchFlags, sk1, sk2, null);
                        return LastIndexOf (s, target, start, length,
                                targetSortKey, ref ctx);
                }
@@ -1803,7 +1791,7 @@ Console.WriteLine ("==== {0} {1} {2} {3} {4} {5} {6} {7} {8}", s, si, send, leng
                        ClearBuffer (targetSortKey, 4);
                        ClearBuffer (sk1, 4);
                        ClearBuffer (sk2, 4);
-                       Context ctx = new Context (opt, alwaysMatchFlags, neverMatchFlags, sk1, sk2, null, false);
+                       Context ctx = new Context (opt, alwaysMatchFlags, neverMatchFlags, sk1, sk2, null);
 
                        // If target is a replacement contraction, then use 
                        // string search.
index 2e6a22b17f5bb71ecc2f387d10e0eb11df475023..87e44f5cda411c2b20d19d34ea2f76ea6e781525 100644 (file)
@@ -171,6 +171,11 @@ namespace System.Globalization
                                                int offset2, int length2,
                                                CompareOptions options)
                {
+                       if (options == CompareOptions.Ordinal)
+                               return string.CompareOrdinalUnchecked (str1, offset1, length1, str2, offset2, length2);
+                       if (options == CompareOptions.OrdinalIgnoreCase)
+                               return string.CompareOrdinalCaseInsensitiveUnchecked (str1, offset1, length1, str2, offset2, length2);
+
                        return UseManagedCollation ?
                                internal_compare_managed (str1, offset1, length1,
                                str2, offset2, length2, options) :