Title: [127227] trunk/Source/WebCore
Revision
127227
Author
[email protected]
Date
2012-08-30 21:00:54 -0700 (Thu, 30 Aug 2012)

Log Message

Loading a worker script should not be O(n^2)
https://bugs.webkit.org/show_bug.cgi?id=95518

Reviewed by Benjamin Poulain.

Previously, we would malloc a new buffer and memcpy the entire worker
script every time we got another packet of data from the network. This
patch uses StringBuilder to accumulate the buffer more efficiently.

* workers/WorkerScriptLoader.cpp:
(WebCore::WorkerScriptLoader::WorkerScriptLoader):
(WebCore::WorkerScriptLoader::didReceiveData):
(WebCore::WorkerScriptLoader::didFinishLoading):
(WebCore):
(WebCore::WorkerScriptLoader::script):
* workers/WorkerScriptLoader.h:
(WorkerScriptLoader):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (127226 => 127227)


--- trunk/Source/WebCore/ChangeLog	2012-08-31 03:48:24 UTC (rev 127226)
+++ trunk/Source/WebCore/ChangeLog	2012-08-31 04:00:54 UTC (rev 127227)
@@ -1,3 +1,23 @@
+2012-08-30  Adam Barth  <[email protected]>
+
+        Loading a worker script should not be O(n^2)
+        https://bugs.webkit.org/show_bug.cgi?id=95518
+
+        Reviewed by Benjamin Poulain.
+
+        Previously, we would malloc a new buffer and memcpy the entire worker
+        script every time we got another packet of data from the network. This
+        patch uses StringBuilder to accumulate the buffer more efficiently.
+
+        * workers/WorkerScriptLoader.cpp:
+        (WebCore::WorkerScriptLoader::WorkerScriptLoader):
+        (WebCore::WorkerScriptLoader::didReceiveData):
+        (WebCore::WorkerScriptLoader::didFinishLoading):
+        (WebCore):
+        (WebCore::WorkerScriptLoader::script):
+        * workers/WorkerScriptLoader.h:
+        (WorkerScriptLoader):
+
 2012-08-30  Yoshifumi Inoue  <[email protected]>
 
         [Forms] Shift+Tab should focus the last field of multiple fields time input UI

Modified: trunk/Source/WebCore/workers/WorkerScriptLoader.cpp (127226 => 127227)


--- trunk/Source/WebCore/workers/WorkerScriptLoader.cpp	2012-08-31 03:48:24 UTC (rev 127226)
+++ trunk/Source/WebCore/workers/WorkerScriptLoader.cpp	2012-08-31 04:00:54 UTC (rev 127227)
@@ -48,7 +48,6 @@
 
 WorkerScriptLoader::WorkerScriptLoader()
     : m_client(0)
-    , m_script("")
     , m_failed(false)
     , m_identifier(0)
     , m_finishing(false)
@@ -146,7 +145,7 @@
     if (len == -1)
         len = strlen(data);
     
-    m_script += m_decoder->decode(data, len);
+    m_script.append(m_decoder->decode(data, len));
 }
 
 void WorkerScriptLoader::didFinishLoading(unsigned long identifier, double)
@@ -157,7 +156,7 @@
     }
 
     if (m_decoder)
-        m_script += m_decoder->flush();
+        m_script.append(m_decoder->flush());
 
     m_identifier = identifier;
     notifyFinished();
@@ -178,7 +177,12 @@
     m_failed = true;
     notifyFinished();
 }
-    
+
+String WorkerScriptLoader::script()
+{
+    return m_script.toString();
+}
+
 void WorkerScriptLoader::notifyFinished()
 {
     if (!m_client || m_finishing)

Modified: trunk/Source/WebCore/workers/WorkerScriptLoader.h (127226 => 127227)


--- trunk/Source/WebCore/workers/WorkerScriptLoader.h	2012-08-31 03:48:24 UTC (rev 127226)
+++ trunk/Source/WebCore/workers/WorkerScriptLoader.h	2012-08-31 04:00:54 UTC (rev 127227)
@@ -38,6 +38,7 @@
 #include <wtf/FastAllocBase.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
+#include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 
@@ -60,7 +61,7 @@
 
         void notifyError();
 
-        const String& script() const { return m_script; }
+        String script();
         const KURL& url() const { return m_url; }
         const KURL& responseURL() const;
         bool failed() const { return m_failed; }
@@ -89,7 +90,7 @@
         RefPtr<ThreadableLoader> m_threadableLoader;
         String m_responseEncoding;        
         RefPtr<TextResourceDecoder> m_decoder;
-        String m_script;
+        StringBuilder m_script;
         KURL m_url;
         KURL m_responseURL;
         bool m_failed;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to