Reviewed by Adele and Adam
authorbeidson <beidson@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Aug 2006 19:00:47 +0000 (19:00 +0000)
committerbeidson <beidson@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Aug 2006 19:00:47 +0000 (19:00 +0000)
        Added an optimization to return early if there's no replacements to be made

        * platform/StringImpl.cpp:
        (WebCore::StringImpl::replace):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16080 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/StringImpl.cpp

index e00c1bf27aa9b0a54583b1d7bf20b4e3e2aacba3..2579849c801f4ad0b32610b2c0604380a824474d 100644 (file)
@@ -1,3 +1,12 @@
+2006-08-28  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Adele and Adam
+
+        Added an optimization to return early if there's no replacements to be made
+
+        * platform/StringImpl.cpp:
+        (WebCore::StringImpl::replace):
+
 2006-08-28  Nikolas Zimmermann  <zimmermann@kde.org>
 
         Reviewed and landed by ap.
index f408c33b230784d95762e58acf1fc23c59d338b5..7d88d6d991cfb38146f9fbd5ba7f5b50ad59686c 100644 (file)
@@ -773,6 +773,10 @@ StringImpl* StringImpl::replace(UChar pattern, const StringImpl* replacement)
         ++srcSegmentStart;
     }
     
+    // If we have 0 matches, we don't have to do any more work
+    if (!matchCount)
+        return this;
+    
     // Create the new StringImpl;
     StringImpl* dst = new StringImpl();
     dst->m_length = m_length - matchCount + (matchCount * repStrLength);