From e5557d43d6934918c018a527f3bae1f7049b9ef1 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 18 Jan 2020 16:08:45 -0500 Subject: Bug 1355479 - Flatten attribute storage in the HTML parser to AutoTArray to avoid malloc. HTML Regen. Tag UXP Issue #1344 --- parser/html/nsHtml5Tokenizer.cpp | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'parser/html/nsHtml5Tokenizer.cpp') diff --git a/parser/html/nsHtml5Tokenizer.cpp b/parser/html/nsHtml5Tokenizer.cpp index aa5b3df28..3b1c34b58 100644 --- a/parser/html/nsHtml5Tokenizer.cpp +++ b/parser/html/nsHtml5Tokenizer.cpp @@ -52,7 +52,6 @@ #include "nsHtml5MetaScanner.h" #include "nsHtml5AttributeName.h" #include "nsHtml5ElementName.h" -#include "nsHtml5HtmlAttributes.h" #include "nsHtml5StackNode.h" #include "nsHtml5UTF16Buffer.h" #include "nsHtml5StateSnapshot.h" @@ -99,6 +98,7 @@ nsHtml5Tokenizer::nsHtml5Tokenizer(nsHtml5TreeBuilder* tokenHandler, bool viewin tagName(nullptr), nonInternedTagName(new nsHtml5ElementName()), attributeName(nullptr), + nonInternedAttributeName(new nsHtml5AttributeName()), doctypeName(nullptr), publicIdentifier(nullptr), systemIdentifier(nullptr), @@ -325,13 +325,16 @@ void nsHtml5Tokenizer::attributeNameComplete() { attributeName = nsHtml5AttributeName::nameByBuffer(strBuf, 0, strBufLen, interner); + if (!attributeName) { + nonInternedAttributeName->setNameForNonInterned(nsHtml5Portability::newLocalNameFromBuffer(strBuf, 0, strBufLen, interner)); + attributeName = nonInternedAttributeName; + } clearStrBufAfterUse(); if (!attributes) { attributes = new nsHtml5HtmlAttributes(0); } if (attributes->contains(attributeName)) { errDuplicateAttribute(); - attributeName->release(); attributeName = nullptr; } } @@ -3941,10 +3944,8 @@ nsHtml5Tokenizer::end() } tagName = nullptr; nonInternedTagName->setNameForNonInterned(nullptr); - if (attributeName) { - attributeName->release(); - attributeName = nullptr; - } + attributeName = nullptr; + nonInternedAttributeName->setNameForNonInterned(nullptr); tokenHandler->endTokenization(); if (attributes) { attributes->clear(0); @@ -3984,13 +3985,8 @@ nsHtml5Tokenizer::resetToDataState() endTag = false; shouldSuspend = false; initDoctypeFields(); - if (tagName) { - tagName = nullptr; - } - if (attributeName) { - attributeName->release(); - attributeName = nullptr; - } + tagName = nullptr; + attributeName = nullptr; if (newAttributesEachTime) { if (attributes) { delete attributes; @@ -4052,13 +4048,13 @@ nsHtml5Tokenizer::loadState(nsHtml5Tokenizer* other) nonInternedTagName->setNameForNonInterned(nsHtml5Portability::newLocalFromLocal(other->tagName->getName(), interner)); tagName = nonInternedTagName; } - if (attributeName) { - attributeName->release(); - } if (!other->attributeName) { attributeName = nullptr; + } else if (other->attributeName->isInterned()) { + attributeName = other->attributeName; } else { - attributeName = other->attributeName->cloneAttributeName(interner); + nonInternedAttributeName->setNameForNonInterned(nsHtml5Portability::newLocalFromLocal(other->attributeName->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML), interner)); + attributeName = nonInternedAttributeName; } delete attributes; if (!other->attributes) { @@ -4089,6 +4085,7 @@ nsHtml5Tokenizer::~nsHtml5Tokenizer() { MOZ_COUNT_DTOR(nsHtml5Tokenizer); delete nonInternedTagName; + delete nonInternedAttributeName; nonInternedTagName = nullptr; delete attributes; attributes = nullptr; -- cgit v1.2.3