Optimize String.Replace when the chars are the same
authorJames Ko <jamesqko@gmail.com>
Thu, 18 Feb 2016 03:41:42 +0000 (22:41 -0500)
committerJames Ko <jamesqko@gmail.com>
Thu, 18 Feb 2016 03:41:42 +0000 (22:41 -0500)
src/classlibnative/bcltype/stringnative.cpp

index 311be11..554e0b9 100644 (file)
@@ -686,6 +686,15 @@ FCIMPL3(LPVOID, COMString::Replace, StringObject* thisRefUNSAFE, CLR_CHAR oldCha
     }
 
     //Perf: If no replacements required, return initial reference
+    
+    // Do it if the chars are the same...
+    
+    if ((WCHAR)oldChar == (WCHAR)newChar)
+    {
+        return thisRefUNSAFE;
+    }
+    
+    // Or if the old char isn't found.
     oldBuffer = thisRef->GetBuffer();
     length = thisRef->GetStringLength();