Use optimized qword path in System.String::EqualsHelper () on 64-bit.
[mono.git] / mcs / class / referencesource / mscorlib / system / string.cs
index 418553dc42d0c72259c1e85988532320cf2c280f..b8df883ebe678e7aba9f34e151c038b87f4bb7d3 100644 (file)
@@ -379,30 +379,31 @@ namespace System {
                 char* b = bp;
 
                 // unroll the loop
-#if AMD64
-                // for AMD64 bit platform we unroll by 12 and
-                // check 3 qword at a time. This is less code
-                // than the 32 bit case and is shorter
-                // pathlength
-
-                while (length >= 12)
-                {
-                    if (*(long*)a     != *(long*)b) return false;
-                    if (*(long*)(a+4) != *(long*)(b+4)) return false;
-                    if (*(long*)(a+8) != *(long*)(b+8)) return false;
-                    a += 12; b += 12; length -= 12;
-                }
-#else
-                while (length >= 10)
-                {
-                    if (*(int*)a != *(int*)b) return false;
-                    if (*(int*)(a+2) != *(int*)(b+2)) return false;
-                    if (*(int*)(a+4) != *(int*)(b+4)) return false;
-                    if (*(int*)(a+6) != *(int*)(b+6)) return false;
-                    if (*(int*)(a+8) != *(int*)(b+8)) return false;
-                    a += 10; b += 10; length -= 10;
+                // the mono jit will inline the 64-bit check and eliminate the irrelevant path
+                if (Environment.Is64BitProcess) {
+                    // for AMD64 bit platform we unroll by 12 and
+                    // check 3 qword at a time. This is less code
+                    // than the 32 bit case and is shorter
+                    // pathlength
+
+                    while (length >= 12)
+                    {
+                        if (*(long*)a     != *(long*)b) return false;
+                        if (*(long*)(a+4) != *(long*)(b+4)) return false;
+                        if (*(long*)(a+8) != *(long*)(b+8)) return false;
+                        a += 12; b += 12; length -= 12;
+                    }
+                } else {
+                    while (length >= 10)
+                    {
+                        if (*(int*)a != *(int*)b) return false;
+                        if (*(int*)(a+2) != *(int*)(b+2)) return false;
+                        if (*(int*)(a+4) != *(int*)(b+4)) return false;
+                        if (*(int*)(a+6) != *(int*)(b+6)) return false;
+                        if (*(int*)(a+8) != *(int*)(b+8)) return false;
+                        a += 10; b += 10; length -= 10;
+                    }
                 }
-#endif
 
                 // This depends on the fact that the String objects are
                 // always zero terminated and that the terminating zero is not included