+2013-11-25 Andreas Kling <akling@apple.com>
+
+ Deduplicate shortish Text node strings during tree construction.
+ <https://webkit.org/b/124855>
+
+ Let HTMLConstructionSite keep a hash set of already seen strings over
+ its lifetime. Use this to deduplicate the strings inside Text nodes
+ for any string up to 64 characters of length.
+
+ This optimization already sort-of existed for whitespace-only Texts,
+ but those are laundered in the AtomicString table which we definitely
+ don't want to pollute with every single Text. It might be a good idea
+ to stop using the AtomicString table for all-whitespace Text too.
+
+ 3.82 MB progression on HTML5-8266 locally.
+
+ Reviewed by Anders Carlsson.
+
2013-11-25 Nick Diego Yamane <nick.yamane@openbossa.org>
Remove unnecessary MediaStreamTrackDescriptor forward declaration
}
while (currentPosition < characters.length()) {
- RefPtr<Text> textNode = Text::createWithLengthLimit(task.parent->document(), shouldUseAtomicString ? AtomicString(characters).string() : characters, currentPosition, lengthLimit);
+ RefPtr<Text> textNode = Text::createWithLengthLimit(task.parent->document(), stringForTextNode(characters, shouldUseAtomicString), currentPosition, lengthLimit);
// If we have a whole string of unbreakable characters the above could lead to an infinite loop. Exceeding the length limit is the lesser evil.
if (!textNode->length()) {
String substring = characters.substring(currentPosition);
- textNode = Text::create(task.parent->document(), shouldUseAtomicString ? AtomicString(substring).string() : substring);
+ textNode = Text::create(task.parent->document(), stringForTextNode(substring, shouldUseAtomicString));
}
currentPosition += textNode->length();
m_attachmentQueue.append(task);
}
+String HTMLConstructionSite::stringForTextNode(const String& string, bool shouldUseAtomicString)
+{
+ static const unsigned maximumLengthForDeduplication = 64;
+ if (shouldUseAtomicString)
+ return AtomicString(string).string();
+ if (string.length() > maximumLengthForDeduplication)
+ return string;
+ return *m_stringsForDeduplication.add(string).iterator;
+}
+
}
void mergeAttributesFromTokenIntoElement(AtomicHTMLToken*, Element*);
void dispatchDocumentElementAvailableIfNeeded();
+ String stringForTextNode(const String&, bool shouldUseAtomicString);
+
Document* m_document;
// This is the root ContainerNode to which the parser attaches all newly
unsigned m_maximumDOMTreeDepth;
bool m_inQuirksMode;
+
+ HashSet<String> m_stringsForDeduplication;
};
} // namespace WebCore