Title: [128126] trunk/Source/WebCore
Revision
128126
Author
[email protected]
Date
2012-09-10 16:23:00 -0700 (Mon, 10 Sep 2012)

Log Message

[V8] V8LazyEventListener::prepareListenerObject uses inefficient string operations
https://bugs.webkit.org/show_bug.cgi?id=96324

Patch by Adam Barth <[email protected]> on 2012-09-10
Reviewed by Kentaro Hara.

Previously, this code called String::append several times, which
mallocs a new string buffer each time. This patch switches this code to
use operator+, which uses StringAppend to optimize these operations
down to a single malloc.

* bindings/v8/V8LazyEventListener.cpp:
(WebCore::V8LazyEventListener::prepareListenerObject):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (128125 => 128126)


--- trunk/Source/WebCore/ChangeLog	2012-09-10 23:22:10 UTC (rev 128125)
+++ trunk/Source/WebCore/ChangeLog	2012-09-10 23:23:00 UTC (rev 128126)
@@ -1,5 +1,20 @@
 2012-09-10  Adam Barth  <[email protected]>
 
+        [V8] V8LazyEventListener::prepareListenerObject uses inefficient string operations
+        https://bugs.webkit.org/show_bug.cgi?id=96324
+
+        Reviewed by Kentaro Hara.
+
+        Previously, this code called String::append several times, which
+        mallocs a new string buffer each time. This patch switches this code to
+        use operator+, which uses StringAppend to optimize these operations
+        down to a single malloc.
+
+        * bindings/v8/V8LazyEventListener.cpp:
+        (WebCore::V8LazyEventListener::prepareListenerObject):
+
+2012-09-10  Adam Barth  <[email protected]>
+
         [V8] V8AuxiliaryContext used by IDB leaks memory
         https://bugs.webkit.org/show_bug.cgi?id=96317
 

Modified: trunk/Source/WebCore/bindings/v8/V8LazyEventListener.cpp (128125 => 128126)


--- trunk/Source/WebCore/bindings/v8/V8LazyEventListener.cpp	2012-09-10 23:22:10 UTC (rev 128125)
+++ trunk/Source/WebCore/bindings/v8/V8LazyEventListener.cpp	2012-09-10 23:23:00 UTC (rev 128126)
@@ -145,16 +145,15 @@
     // Call with 4 arguments instead of 3, pass additional null as the last parameter.
     // By calling the function with 4 arguments, we create a setter on arguments object
     // which would shadow property "3" on the prototype.
-    String code = ASCIILiteral("(function() {" \
-        "with (this[2]) {" \
-        "with (this[1]) {" \
-        "with (this[0]) {");
-    code.append("return function(");
-    code.append(m_eventParameterName);
-    code.append(") {");
-    code.append(m_code);
-    // Insert '\n' otherwise //-style comments could break the handler.
-    code.append("\n};}}}})");
+    String code = "(function() {"
+        "with (this[2]) {"
+        "with (this[1]) {"
+        "with (this[0]) {"
+            "return function(" + m_eventParameterName + ") {" +
+                m_code + "\n" // Insert '\n' otherwise //-style comments could break the handler.
+            "};"
+        "}}}})";
+
     v8::Handle<v8::String> codeExternalString = v8ExternalString(code);
 
     v8::Handle<v8::Script> script = ScriptSourceCode::compileScript(codeExternalString, m_sourceURL, m_position);
@@ -219,14 +218,8 @@
     if (!toStringTemplate.IsEmpty())
         toStringFunction = toStringTemplate->GetFunction();
     if (!toStringFunction.IsEmpty()) {
-        String toStringResult = ASCIILiteral("function ");
-        toStringResult.append(m_functionName);
-        toStringResult.append("(");
-        toStringResult.append(m_eventParameterName);
-        toStringResult.append(") {\n  ");
-        toStringResult.append(m_code);
-        toStringResult.append("\n}");
-        wrappedFunction->SetHiddenValue(V8HiddenPropertyName::toStringString(), v8ExternalString(toStringResult));
+        String toStringString = "function " + m_functionName + "(" + m_eventParameterName + ") {\n  " + m_code + "\n}";
+        wrappedFunction->SetHiddenValue(V8HiddenPropertyName::toStringString(), v8ExternalString(toStringString));
         wrappedFunction->Set(v8::String::NewSymbol("toString"), toStringFunction);
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to