Title: [151236] trunk/Source/WebCore
- Revision
- 151236
- Author
- [email protected]
- Date
- 2013-06-05 14:20:40 -0700 (Wed, 05 Jun 2013)
Log Message
Avoid multiple copies of inline script & style strings
https://bugs.webkit.org/show_bug.cgi?id=117202
Patch by Arunprasad Rajkumar <[email protected]> on 2013-06-05
Reviewed by Darin Adler.
Merge from https://chromiumcodereview.appspot.com/16005007.
No new tests needed.
The HTML parser breaks up large text nodes into small chunks to avoid some
O(n^2) editing algorithms. This fix skips that workaround for <script> and
<style> elements, which aren't likely to need editing. As a result, <script>
ends up with a single text node, containing a contiguous String, which is the
source code of that inline script block.
Prior this fix, we could end up with two copies of large inline scripts: one
monolithic string retained by JSC and a number of shards retained by the DOM.
After this fix, both the DOM and JSC use the same monolithic string, removing a
copy.
* dom/Text.cpp:
(WebCore::Text::createWithLengthLimit):
* html/parser/HTMLConstructionSite.cpp:
(WebCore::shouldUseLengthLimit):
(WebCore::HTMLConstructionSite::insertTextNode):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (151235 => 151236)
--- trunk/Source/WebCore/ChangeLog 2013-06-05 19:57:53 UTC (rev 151235)
+++ trunk/Source/WebCore/ChangeLog 2013-06-05 21:20:40 UTC (rev 151236)
@@ -1,3 +1,31 @@
+2013-06-05 Arunprasad Rajkumar <[email protected]>
+
+ Avoid multiple copies of inline script & style strings
+ https://bugs.webkit.org/show_bug.cgi?id=117202
+
+ Reviewed by Darin Adler.
+
+ Merge from https://chromiumcodereview.appspot.com/16005007.
+
+ No new tests needed.
+
+ The HTML parser breaks up large text nodes into small chunks to avoid some
+ O(n^2) editing algorithms. This fix skips that workaround for <script> and
+ <style> elements, which aren't likely to need editing. As a result, <script>
+ ends up with a single text node, containing a contiguous String, which is the
+ source code of that inline script block.
+
+ Prior this fix, we could end up with two copies of large inline scripts: one
+ monolithic string retained by JSC and a number of shards retained by the DOM.
+ After this fix, both the DOM and JSC use the same monolithic string, removing a
+ copy.
+
+ * dom/Text.cpp:
+ (WebCore::Text::createWithLengthLimit):
+ * html/parser/HTMLConstructionSite.cpp:
+ (WebCore::shouldUseLengthLimit):
+ (WebCore::HTMLConstructionSite::insertTextNode):
+
2013-06-05 Kondapally Kalyan <[email protected]>
[EFL] Build fix with EGL and GLES2 backend.
Modified: trunk/Source/WebCore/dom/Text.cpp (151235 => 151236)
--- trunk/Source/WebCore/dom/Text.cpp 2013-06-05 19:57:53 UTC (rev 151235)
+++ trunk/Source/WebCore/dom/Text.cpp 2013-06-05 21:20:40 UTC (rev 151236)
@@ -326,15 +326,15 @@
return create(document(), data);
}
-PassRefPtr<Text> Text::createWithLengthLimit(Document* document, const String& data, unsigned start, unsigned maxChars)
+PassRefPtr<Text> Text::createWithLengthLimit(Document* document, const String& data, unsigned start, unsigned lengthLimit)
{
unsigned dataLength = data.length();
- if (!start && dataLength <= maxChars)
+ if (!start && dataLength <= lengthLimit)
return create(document, data);
RefPtr<Text> result = Text::create(document, String());
- result->parserAppendData(data, start, maxChars);
+ result->parserAppendData(data, start, lengthLimit);
return result;
}
Modified: trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp (151235 => 151236)
--- trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp 2013-06-05 19:57:53 UTC (rev 151235)
+++ trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp 2013-06-05 21:20:40 UTC (rev 151236)
@@ -75,6 +75,13 @@
|| item->hasTagName(rtTag);
}
+static bool shouldUseLengthLimit(const ContainerNode* node)
+{
+ return !node->hasTagName(scriptTag)
+ && !node->hasTagName(styleTag)
+ && !node->hasTagName(SVGNames::scriptTag);
+}
+
static inline bool isAllWhitespace(const String& string)
{
return string.isAllSpecialCharacters<isHTMLSpace>();
@@ -490,6 +497,7 @@
|| (whitespaceMode == WhitespaceUnknown && isAllWhitespace(characters));
unsigned currentPosition = 0;
+ unsigned lengthLimit = shouldUseLengthLimit(task.parent.get()) ? Text::defaultLengthLimit : std::numeric_limits<unsigned>::max();
// FIXME: Splitting text nodes into smaller chunks contradicts HTML5 spec, but is currently necessary
// for performance, see <https://bugs.webkit.org/show_bug.cgi?id=55898>.
@@ -499,11 +507,11 @@
// FIXME: We're only supposed to append to this text node if it
// was the last text node inserted by the parser.
CharacterData* textNode = static_cast<CharacterData*>(previousChild);
- currentPosition = textNode->parserAppendData(characters, 0, Text::defaultLengthLimit);
+ currentPosition = textNode->parserAppendData(characters, 0, lengthLimit);
}
while (currentPosition < characters.length()) {
- RefPtr<Text> textNode = Text::createWithLengthLimit(task.parent->document(), shouldUseAtomicString ? AtomicString(characters).string() : characters, currentPosition);
+ RefPtr<Text> textNode = Text::createWithLengthLimit(task.parent->document(), shouldUseAtomicString ? AtomicString(characters).string() : characters, 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);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes