[JSC] JSString::getIndex() should avoid reifying substrings.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jun 2015 18:03:40 +0000 (18:03 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jun 2015 18:03:40 +0000 (18:03 +0000)
<https://webkit.org/b/145803>

Reviewed by Darin Adler.

Implement getIndex() using JSString::view(), which cuts it down to a one-liner
and also avoids reifying substrings.

I saw 178 kB of reified substrings below operationGetByVal -> getIndex()
on cnet.com, so this should help.

* runtime/JSString.cpp:
(JSC::JSRopeString::getIndexSlowCase): Deleted.
* runtime/JSString.h:
(JSC::JSString::getIndex):

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSString.cpp
Source/JavaScriptCore/runtime/JSString.h

index b9e229c..5332cac 100644 (file)
@@ -1,5 +1,23 @@
 2015-06-09  Andreas Kling  <akling@apple.com>
 
+        [JSC] JSString::getIndex() should avoid reifying substrings.
+        <https://webkit.org/b/145803>
+
+        Reviewed by Darin Adler.
+
+        Implement getIndex() using JSString::view(), which cuts it down to a one-liner
+        and also avoids reifying substrings.
+
+        I saw 178 kB of reified substrings below operationGetByVal -> getIndex()
+        on cnet.com, so this should help.
+
+        * runtime/JSString.cpp:
+        (JSC::JSRopeString::getIndexSlowCase): Deleted.
+        * runtime/JSString.h:
+        (JSC::JSString::getIndex):
+
+2015-06-09  Andreas Kling  <akling@apple.com>
+
         [JSC] String.prototype.indexOf() should use StringView.
         <https://webkit.org/b/145351>
 
index 8c7ec08..eb046ed 100644 (file)
@@ -365,18 +365,6 @@ void JSRopeString::outOfMemory(ExecState* exec) const
         throwOutOfMemoryError(exec);
 }
 
-JSString* JSRopeString::getIndexSlowCase(ExecState* exec, unsigned i)
-{
-    ASSERT(isRope());
-    resolveRope(exec);
-    // Return a safe no-value result, this should never be used, since the excetion will be thrown.
-    if (exec->exception())
-        return jsEmptyString(exec);
-    ASSERT(!isRope());
-    RELEASE_ASSERT(i < m_value.length());
-    return jsSingleCharacterString(exec, m_value[i]);
-}
-
 JSValue JSString::toPrimitive(ExecState*, PreferredPrimitiveType) const
 {
     return const_cast<JSString*>(this);
index d4969db..170c683 100644 (file)
@@ -372,8 +372,6 @@ private:
     void clearFibers() const;
     StringView view(ExecState*) const;
 
-    JS_EXPORT_PRIVATE JSString* getIndexSlowCase(ExecState*, unsigned);
-
     WriteBarrierBase<JSString>& fiber(unsigned i) const
     {
         ASSERT(!isSubstring());
@@ -493,10 +491,7 @@ inline const String& JSString::tryGetValue() const
 inline JSString* JSString::getIndex(ExecState* exec, unsigned i)
 {
     ASSERT(canGetIndex(i));
-    if (isRope())
-        return static_cast<JSRopeString*>(this)->getIndexSlowCase(exec, i);
-    ASSERT(i < m_value.length());
-    return jsSingleCharacterString(exec, m_value[i]);
+    return jsSingleCharacterString(exec, view(exec)[i]);
 }
 
 inline JSString* jsString(VM* vm, const String& s)