Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(880)

Unified Diff: Source/core/html/parser/HTMLTreeBuilder.cpp

Issue 26129005: Rewrite Text node attaching to not be N^2 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Flush for foriegn content also Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/parser/HTMLTreeBuilder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/parser/HTMLTreeBuilder.cpp
diff --git a/Source/core/html/parser/HTMLTreeBuilder.cpp b/Source/core/html/parser/HTMLTreeBuilder.cpp
index 1c910153d31a30fcb46b03a7fde4c2d1235602d5..0553f7384f9054e234ed2df991d0f728c1e81317 100644
--- a/Source/core/html/parser/HTMLTreeBuilder.cpp
+++ b/Source/core/html/parser/HTMLTreeBuilder.cpp
@@ -358,6 +358,7 @@ HTMLTreeBuilder::FragmentParsingContext::~FragmentParsingContext()
PassRefPtr<Element> HTMLTreeBuilder::takeScriptToProcess(TextPosition& scriptStartPosition)
{
ASSERT(m_scriptToProcess);
+ ASSERT(!m_tree.hasPendingTasks());
// Unpause ourselves, callers may pause us again when processing the script.
// The HTML5 spec is written as though scripts are executed inside the tree
// builder. We pause the parser to exit the tree builder, and then resume
@@ -398,6 +399,9 @@ void HTMLTreeBuilder::processToken(AtomicHTMLToken* token)
return;
}
+ // Any non-character token needs to cause us to flush any pending text immediately.
+ // NOTE: flush() can cause any queued tasks to execute, possibly re-entering the parser.
+ m_tree.flush();
m_shouldSkipLeadingNewline = false;
switch (token->type()) {
@@ -2717,6 +2721,15 @@ bool HTMLTreeBuilder::shouldProcessTokenInForeignContent(AtomicHTMLToken* token)
void HTMLTreeBuilder::processTokenInForeignContent(AtomicHTMLToken* token)
{
+ if (token->type() == HTMLToken::Character) {
+ const String& characters = token->characters();
+ m_tree.insertTextNode(characters);
+ if (m_framesetOk && !isAllWhitespaceOrReplacementCharacters(characters))
+ m_framesetOk = false;
+ return;
+ }
+
+ m_tree.flush();
RefPtr<HTMLStackItem> adjustedCurrentNode = adjustedCurrentStackItem();
switch (token->type()) {
@@ -2815,14 +2828,8 @@ void HTMLTreeBuilder::processTokenInForeignContent(AtomicHTMLToken* token)
}
case HTMLToken::Comment:
m_tree.insertComment(token);
- return;
- case HTMLToken::Character: {
- const String& characters = token->characters();
- m_tree.insertTextNode(characters);
- if (m_framesetOk && !isAllWhitespaceOrReplacementCharacters(characters))
- m_framesetOk = false;
break;
- }
+ case HTMLToken::Character:
case HTMLToken::EndOfFile:
ASSERT_NOT_REACHED();
break;
« no previous file with comments | « Source/core/html/parser/HTMLTreeBuilder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698