From 351091dcb99061d735cc2792139e737a8ead93dd Mon Sep 17 00:00:00 2001 From: James Ko Date: Wed, 17 Feb 2016 22:41:42 -0500 Subject: [PATCH] Optimize String.Replace when the chars are the same --- src/classlibnative/bcltype/stringnative.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/classlibnative/bcltype/stringnative.cpp b/src/classlibnative/bcltype/stringnative.cpp index 311be11..554e0b9 100644 --- a/src/classlibnative/bcltype/stringnative.cpp +++ b/src/classlibnative/bcltype/stringnative.cpp @@ -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(); -- 2.7.4