Document source preload scanned repeatedly
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Apr 2011 18:17:49 +0000 (18:17 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Apr 2011 18:17:49 +0000 (18:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=58123

Reviewed by Tony Gentilcore.

Don't clear the preload scanner after execution resumes. This would lose the current
scanning point and lead to rescanning when the preload scanner would get reconstructed
due to main parser blocking again.

Instead clear the scanner only in the specific case of receiving new data while the main
parser has already reached the end of the current input.

Also switched to using isWaitingForScripts() instead of m_treeBuilder->isPaused() for consistency.

The case the clearing in resumeParsingAfterScriptExecution() was added for is covered by
http/tests/loading/preload-slow-loading.php.

* html/parser/HTMLDocumentParser.cpp:
(WebCore::HTMLDocumentParser::insert):
(WebCore::HTMLDocumentParser::append):
(WebCore::HTMLDocumentParser::resumeParsingAfterScriptExecution):

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

Source/WebCore/ChangeLog
Source/WebCore/html/parser/HTMLDocumentParser.cpp

index 6eaffcb..b6495e8 100644 (file)
@@ -1,3 +1,27 @@
+2011-04-11  Antti Koivisto  <antti@apple.com>
+
+        Reviewed by Tony Gentilcore.
+
+        Document source preload scanned repeatedly
+        https://bugs.webkit.org/show_bug.cgi?id=58123
+        
+        Don't clear the preload scanner after execution resumes. This would lose the current
+        scanning point and lead to rescanning when the preload scanner would get reconstructed
+        due to main parser blocking again.
+
+        Instead clear the scanner only in the specific case of receiving new data while the main
+        parser has already reached the end of the current input.
+
+        Also switched to using isWaitingForScripts() instead of m_treeBuilder->isPaused() for consistency.
+
+        The case the clearing in resumeParsingAfterScriptExecution() was added for is covered by 
+        http/tests/loading/preload-slow-loading.php.
+
+        * html/parser/HTMLDocumentParser.cpp:
+        (WebCore::HTMLDocumentParser::insert):
+        (WebCore::HTMLDocumentParser::append):
+        (WebCore::HTMLDocumentParser::resumeParsingAfterScriptExecution):
+
 2011-04-11  Dan Bernstein  <mitz@apple.com>
 
         Build fix.
index a9e9fe5..b49e667 100644 (file)
@@ -324,7 +324,7 @@ void HTMLDocumentParser::insert(const SegmentedString& source)
     m_input.insertAtCurrentInsertionPoint(excludedLineNumberSource);
     pumpTokenizerIfPossible(ForceSynchronous);
     
-    if (m_treeBuilder->isPaused()) {
+    if (isWaitingForScripts()) {
         // Check the document.write() output with a separate preload scanner as
         // the main scanner can't deal with insertions.
         HTMLPreloadScanner preloadScanner(document());
@@ -344,13 +344,20 @@ void HTMLDocumentParser::append(const SegmentedString& source)
     // but we need to ensure it isn't deleted yet.
     RefPtr<HTMLDocumentParser> protect(this);
 
-    m_input.appendToEnd(source);
     if (m_preloadScanner) {
-        m_preloadScanner->appendToEnd(source);
-        if (m_treeBuilder->isPaused())
-            m_preloadScanner->scan();
+        if (m_input.current().isEmpty() && !isWaitingForScripts()) {
+            // We have parsed until the end of the current input and so are now moving ahead of the preload scanner.
+            // Clear the scanner so we know to scan starting from the current input point if we block again.
+            m_preloadScanner.clear();
+        } else {
+            m_preloadScanner->appendToEnd(source);
+            if (isWaitingForScripts())
+                m_preloadScanner->scan();
+        }
     }
 
+    m_input.appendToEnd(source);
+
     if (inPumpSession()) {
         // We've gotten data off the network in a nested write.
         // We don't want to consume any more of the input stream now.  Do
@@ -470,7 +477,6 @@ void HTMLDocumentParser::resumeParsingAfterScriptExecution()
     ASSERT(!inScriptExecution());
     ASSERT(!m_treeBuilder->isPaused());
 
-    m_preloadScanner.clear();
     pumpTokenizerIfPossible(AllowYield);
     endIfDelayed();
 }