Title: [165054] trunk/Source
Revision
165054
Author
[email protected]
Date
2014-03-04 09:05:26 -0800 (Tue, 04 Mar 2014)

Log Message

Micro-optimize Strings in JS bindings.
<https://webkit.org/b/129673>

Source/_javascript_Core:

Make jsStringWithWeakOwner() take a StringImpl& instead of a String.
This avoids branches in length() and operator[].

Also call JSString::create() directly instead of jsString() and just
assert that the string length is >1. This way we don't duplicate the
optimizations for empty and single-character strings.

Reviewed by Ryosuke Niwa.

* runtime/JSString.h:
(JSC::jsStringWithWeakOwner):

Source/WebCore:

Tweaked for new jsStringWithWeakOwner signature. This patch removes
36 bytes of code from every wrapper getter that returns a DOMString.

Reviewed by Ryosuke Niwa.

* bindings/js/JSDOMBinding.h:
(WebCore::jsStringWithCache):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (165053 => 165054)


--- trunk/Source/_javascript_Core/ChangeLog	2014-03-04 17:02:05 UTC (rev 165053)
+++ trunk/Source/_javascript_Core/ChangeLog	2014-03-04 17:05:26 UTC (rev 165054)
@@ -1,3 +1,20 @@
+2014-03-04  Andreas Kling  <[email protected]>
+
+        Micro-optimize Strings in JS bindings.
+        <https://webkit.org/b/129673>
+
+        Make jsStringWithWeakOwner() take a StringImpl& instead of a String.
+        This avoids branches in length() and operator[].
+
+        Also call JSString::create() directly instead of jsString() and just
+        assert that the string length is >1. This way we don't duplicate the
+        optimizations for empty and single-character strings.
+
+        Reviewed by Ryosuke Niwa.
+
+        * runtime/JSString.h:
+        (JSC::jsStringWithWeakOwner):
+
 2014-03-04  Dániel Bátyai  <[email protected]>
 
         Implement Number.prototype.clz()

Modified: trunk/Source/_javascript_Core/runtime/JSString.h (165053 => 165054)


--- trunk/Source/_javascript_Core/runtime/JSString.h	2014-03-04 17:02:05 UTC (rev 165053)
+++ trunk/Source/_javascript_Core/runtime/JSString.h	2014-03-04 17:05:26 UTC (rev 165054)
@@ -412,25 +412,27 @@
         return JSString::create(*vm, s.impl());
     }
 
-    inline JSString* jsStringWithWeakOwner(VM* vm, const String& s)
+    inline JSString* jsStringWithWeakOwner(VM& vm, StringImpl& stringImpl)
     {
-        WeakHandleOwner* jsStringWeakOwner = vm->jsStringWeakOwner.get();
-        StringImpl* impl = s.impl();
+        WeakHandleOwner* jsStringWeakOwner = vm.jsStringWeakOwner.get();
 
-        // If this vm is not allowed to weakly own strings just call jsString.
-        if (!jsStringWeakOwner || !impl)
-            return jsString(vm, s);
+        // Should have picked a VM-global empty or single-character string already.
+        ASSERT(stringImpl.length() > 1);
 
+        // If this VM is not allowed to weakly own strings just make a new JSString.
+        if (!jsStringWeakOwner)
+            return JSString::create(vm, &stringImpl);
+
         // Check for an existing weakly owned JSString.
-        if (WeakImpl* weakImpl = impl->weakJSString()) {
+        if (WeakImpl* weakImpl = stringImpl.weakJSString()) {
             if (weakImpl->state() == WeakImpl::Live)
                 return asString(weakImpl->jsValue());
             WeakSet::deallocate(weakImpl);
-            impl->setWeakJSString(nullptr);
+            stringImpl.setWeakJSString(nullptr);
         }
 
-        JSString* string = jsString(vm, s);
-        impl->setWeakJSString(WeakSet::allocate(string, jsStringWeakOwner, impl));
+        JSString* string = JSString::create(vm, &stringImpl);
+        stringImpl.setWeakJSString(WeakSet::allocate(string, jsStringWeakOwner, &stringImpl));
         return string;
     }
 

Modified: trunk/Source/WebCore/ChangeLog (165053 => 165054)


--- trunk/Source/WebCore/ChangeLog	2014-03-04 17:02:05 UTC (rev 165053)
+++ trunk/Source/WebCore/ChangeLog	2014-03-04 17:05:26 UTC (rev 165054)
@@ -1,3 +1,16 @@
+2014-03-04  Andreas Kling  <[email protected]>
+
+        Micro-optimize Strings in JS bindings.
+        <https://webkit.org/b/129673>
+
+        Tweaked for new jsStringWithWeakOwner signature. This patch removes
+        36 bytes of code from every wrapper getter that returns a DOMString.
+
+        Reviewed by Ryosuke Niwa.
+
+        * bindings/js/JSDOMBinding.h:
+        (WebCore::jsStringWithCache):
+
 2014-03-03  David Kilzer  <[email protected]>
 
         SVGPropertyTearOffs should detachChildren before deleting its value.

Modified: trunk/Source/WebCore/bindings/js/JSDOMBinding.h (165053 => 165054)


--- trunk/Source/WebCore/bindings/js/JSDOMBinding.h	2014-03-04 17:02:05 UTC (rev 165053)
+++ trunk/Source/WebCore/bindings/js/JSDOMBinding.h	2014-03-04 17:05:26 UTC (rev 165054)
@@ -571,19 +571,19 @@
 
 inline JSC::JSValue jsStringWithCache(JSC::ExecState* exec, const String& s)
 {
+    JSC::VM& vm = exec->vm();
+
     StringImpl* stringImpl = s.impl();
     if (!stringImpl || !stringImpl->length())
-        return jsEmptyString(exec);
+        return jsEmptyString(&vm);
 
     if (stringImpl->length() == 1) {
         UChar singleCharacter = (*stringImpl)[0u];
-        if (singleCharacter <= JSC::maxSingleCharacterString) {
-            JSC::VM* vm = &exec->vm();
-            return vm->smallStrings.singleCharacterString(static_cast<unsigned char>(singleCharacter));
-        }
+        if (singleCharacter <= JSC::maxSingleCharacterString)
+            return vm.smallStrings.singleCharacterString(static_cast<unsigned char>(singleCharacter));
     }
 
-    return JSC::jsStringWithWeakOwner(&exec->vm(), s);
+    return JSC::jsStringWithWeakOwner(vm, *stringImpl);
 }
 
 inline String propertyNameToString(JSC::PropertyName propertyName)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to