Factored out some code into a helper function.
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Jan 2012 02:00:44 +0000 (02:00 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Jan 2012 02:00:44 +0000 (02:00 +0000)
I think this might help getting rid of omit-frame-pointer.

Reviewed by Sam Weinig.

No benchmark change.

* runtime/StringPrototype.cpp:
(JSC::removeUsingRegExpSearch): Moved to here...
(JSC::replaceUsingRegExpSearch): ...from here.

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/StringPrototype.cpp

index dc691d7..6f41cbc 100644 (file)
@@ -1,3 +1,17 @@
+2012-01-17  Geoffrey Garen  <ggaren@apple.com>
+
+        Factored out some code into a helper function.
+        
+        I think this might help getting rid of omit-frame-pointer.
+
+        Reviewed by Sam Weinig.
+        
+        No benchmark change.
+
+        * runtime/StringPrototype.cpp:
+        (JSC::removeUsingRegExpSearch): Moved to here...
+        (JSC::replaceUsingRegExpSearch): ...from here.
+
 2012-01-17  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
 
         Uint8ClampedArray support
index 740916a..3736676 100644 (file)
@@ -398,6 +398,47 @@ static ALWAYS_INLINE JSValue jsSpliceSubstringsWithSeparators(ExecState* exec, J
     return jsString(exec, impl.release());
 }
 
+static NEVER_INLINE EncodedJSValue removeUsingRegExpSearch(ExecState* exec, JSString* string, const UString& source, RegExp* regExp)
+{
+    int lastIndex = 0;
+    unsigned startPosition = 0;
+
+    Vector<StringRange, 16> sourceRanges;
+    JSGlobalData* globalData = &exec->globalData();
+    RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
+    unsigned sourceLen = source.length();
+
+    while (true) {
+        int matchIndex;
+        int matchLen = 0;
+        int* ovector;
+        regExpConstructor->performMatch(*globalData, regExp, source, startPosition, matchIndex, matchLen, &ovector);
+        if (matchIndex < 0)
+            break;
+
+        if (lastIndex < matchIndex)
+            sourceRanges.append(StringRange(lastIndex, matchIndex - lastIndex));
+
+        lastIndex = matchIndex + matchLen;
+        startPosition = lastIndex;
+
+        // special case of empty match
+        if (!matchLen) {
+            startPosition++;
+            if (startPosition > sourceLen)
+                break;
+        }
+    }
+
+    if (!lastIndex)
+        return JSValue::encode(string);
+
+    if (static_cast<unsigned>(lastIndex) < sourceLen)
+        sourceRanges.append(StringRange(lastIndex, sourceLen - lastIndex));
+
+    return JSValue::encode(jsSpliceSubstrings(exec, string, source, sourceRanges.data(), sourceRanges.size()));
+}
+
 static NEVER_INLINE EncodedJSValue replaceUsingRegExpSearch(ExecState* exec, JSString* string, JSValue searchValue, JSValue replaceValue)
 {
     UString replacementString;
@@ -413,45 +454,10 @@ static NEVER_INLINE EncodedJSValue replaceUsingRegExpSearch(ExecState* exec, JSS
     RegExp* regExp = asRegExpObject(searchValue)->regExp();
     bool global = regExp->global();
 
-    RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
-
-    // Optimization for substring removal (replace with empty).
-    if (global && callType == CallTypeNone && !replacementString.length()) {
-        int lastIndex = 0;
-        unsigned startPosition = 0;
+    if (global && callType == CallTypeNone && !replacementString.length())
+        return removeUsingRegExpSearch(exec, string, source, regExp);
 
-        Vector<StringRange, 16> sourceRanges;
-        JSGlobalData* globalData = &exec->globalData();
-        while (true) {
-            int matchIndex;
-            int matchLen = 0;
-            int* ovector;
-            regExpConstructor->performMatch(*globalData, regExp, source, startPosition, matchIndex, matchLen, &ovector);
-            if (matchIndex < 0)
-                break;
-
-            if (lastIndex < matchIndex)
-                sourceRanges.append(StringRange(lastIndex, matchIndex - lastIndex));
-
-            lastIndex = matchIndex + matchLen;
-            startPosition = lastIndex;
-
-            // special case of empty match
-            if (!matchLen) {
-                startPosition++;
-                if (startPosition > sourceLen)
-                    break;
-            }
-        }
-
-        if (!lastIndex)
-            return JSValue::encode(string);
-
-        if (static_cast<unsigned>(lastIndex) < sourceLen)
-            sourceRanges.append(StringRange(lastIndex, sourceLen - lastIndex));
-
-        return JSValue::encode(jsSpliceSubstrings(exec, string, source, sourceRanges.data(), sourceRanges.size()));
-    }
+    RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
 
     int lastIndex = 0;
     unsigned startPosition = 0;