Reduce JSC API static value setter/getter overhead.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Jul 2013 23:57:23 +0000 (23:57 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Jul 2013 23:57:23 +0000 (23:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=119277

Patch by Yi Shen <max.hong.shen@gmail.com> on 2013-07-31
Reviewed by Geoffrey Garen.

Add property name to the static value entry, so that OpaqueJSString::create() doesn't
need to get called every time when set or get the static value.

* API/JSCallbackObjectFunctions.h:
(JSC::::put):
(JSC::::putByIndex):
(JSC::::getStaticValue):
* API/JSClassRef.cpp:
(OpaqueJSClassContextData::OpaqueJSClassContextData):
* API/JSClassRef.h:
(StaticValueEntry::StaticValueEntry):

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

Source/JavaScriptCore/API/JSCallbackObjectFunctions.h
Source/JavaScriptCore/API/JSClassRef.cpp
Source/JavaScriptCore/API/JSClassRef.h
Source/JavaScriptCore/ChangeLog

index 8996ae3..efb6518 100644 (file)
@@ -263,13 +263,11 @@ void JSCallbackObject<Parent>::put(JSCell* cell, ExecState* exec, PropertyName p
                     if (entry->attributes & kJSPropertyAttributeReadOnly)
                         return;
                     if (JSObjectSetPropertyCallback setProperty = entry->setProperty) {
-                        if (!propertyNameRef)
-                            propertyNameRef = OpaqueJSString::create(name);
                         JSValueRef exception = 0;
                         bool result;
                         {
                             APICallbackShim callbackShim(exec);
-                            result = setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, &exception);
+                            result = setProperty(ctx, thisRef, entry->propertyNameRef.get(), valueRef, &exception);
                         }
                         if (exception)
                             throwError(exec, toJS(exec, exception));
@@ -324,13 +322,11 @@ void JSCallbackObject<Parent>::putByIndex(JSCell* cell, ExecState* exec, unsigne
                 if (entry->attributes & kJSPropertyAttributeReadOnly)
                     return;
                 if (JSObjectSetPropertyCallback setProperty = entry->setProperty) {
-                    if (!propertyNameRef)
-                        propertyNameRef = OpaqueJSString::create(propertyName.impl());
                     JSValueRef exception = 0;
                     bool result;
                     {
                         APICallbackShim callbackShim(exec);
-                        result = setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, &exception);
+                        result = setProperty(ctx, thisRef, entry->propertyNameRef.get(), valueRef, &exception);
                     }
                     if (exception)
                         throwError(exec, toJS(exec, exception));
@@ -580,20 +576,17 @@ template <class Parent>
 JSValue JSCallbackObject<Parent>::getStaticValue(ExecState* exec, PropertyName propertyName)
 {
     JSObjectRef thisRef = toRef(this);
-    RefPtr<OpaqueJSString> propertyNameRef;
     
     if (StringImpl* name = propertyName.publicName()) {
         for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
             if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
                 if (StaticValueEntry* entry = staticValues->get(name)) {
                     if (JSObjectGetPropertyCallback getProperty = entry->getProperty) {
-                        if (!propertyNameRef)
-                            propertyNameRef = OpaqueJSString::create(name);
                         JSValueRef exception = 0;
                         JSValueRef value;
                         {
                             APICallbackShim callbackShim(exec);
-                            value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), &exception);
+                            value = getProperty(toRef(exec), thisRef, entry->propertyNameRef.get(), &exception);
                         }
                         if (exception) {
                             throwError(exec, toJS(exec, exception));
index c77f63c..76d0c5a 100644 (file)
@@ -66,7 +66,7 @@ OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass*
         while (staticValue->name) {
             String valueName = String::fromUTF8(staticValue->name);
             if (!valueName.isNull())
-                m_staticValues->set(valueName.impl(), adoptPtr(new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes)));
+                m_staticValues->set(valueName.impl(), adoptPtr(new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes, valueName)));
             ++staticValue;
         }
     }
@@ -135,7 +135,8 @@ OpaqueJSClassContextData::OpaqueJSClassContextData(JSC::VM&, OpaqueJSClass* jsCl
         OpaqueJSClassStaticValuesTable::const_iterator end = jsClass->m_staticValues->end();
         for (OpaqueJSClassStaticValuesTable::const_iterator it = jsClass->m_staticValues->begin(); it != end; ++it) {
             ASSERT(!it->key->isIdentifier());
-            staticValues->add(it->key->isolatedCopy(), adoptPtr(new StaticValueEntry(it->value->getProperty, it->value->setProperty, it->value->attributes)));
+            String valueName = it->key->isolatedCopy();
+            staticValues->add(valueName.impl(), adoptPtr(new StaticValueEntry(it->value->getProperty, it->value->setProperty, it->value->attributes, valueName)));
         }
     }
 
index 7bf18e7..d1cddfe 100644 (file)
 #ifndef JSClassRef_h
 #define JSClassRef_h
 
-#include <JavaScriptCore/JSObjectRef.h>
-
-#include "Weak.h"
+#include "OpaqueJSString.h"
 #include "Protect.h"
+#include "Weak.h"
+#include <JavaScriptCore/JSObjectRef.h>
 #include <wtf/HashMap.h>
 #include <wtf/text/WTFString.h>
 
 struct StaticValueEntry {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    StaticValueEntry(JSObjectGetPropertyCallback _getProperty, JSObjectSetPropertyCallback _setProperty, JSPropertyAttributes _attributes)
-        : getProperty(_getProperty), setProperty(_setProperty), attributes(_attributes)
+    StaticValueEntry(JSObjectGetPropertyCallback _getProperty, JSObjectSetPropertyCallback _setProperty, JSPropertyAttributes _attributes, String& propertyName)
+    : getProperty(_getProperty), setProperty(_setProperty), attributes(_attributes), propertyNameRef(OpaqueJSString::create(propertyName))
     {
     }
     
     JSObjectGetPropertyCallback getProperty;
     JSObjectSetPropertyCallback setProperty;
     JSPropertyAttributes attributes;
+    RefPtr<OpaqueJSString> propertyNameRef;
 };
 
 struct StaticFunctionEntry {
index 5544cae..d35e58a 100644 (file)
@@ -1,3 +1,22 @@
+2013-07-31  Yi Shen  <max.hong.shen@gmail.com>
+
+        Reduce JSC API static value setter/getter overhead.
+        https://bugs.webkit.org/show_bug.cgi?id=119277
+
+        Reviewed by Geoffrey Garen.
+
+        Add property name to the static value entry, so that OpaqueJSString::create() doesn't
+        need to get called every time when set or get the static value.
+
+        * API/JSCallbackObjectFunctions.h:
+        (JSC::::put):
+        (JSC::::putByIndex):
+        (JSC::::getStaticValue):
+        * API/JSClassRef.cpp:
+        (OpaqueJSClassContextData::OpaqueJSClassContextData):
+        * API/JSClassRef.h:
+        (StaticValueEntry::StaticValueEntry):
+
 2013-07-31  Kwang Yul Seo  <skyul@company100.net>
 
         Use emptyString instead of String("")