From 650f6b5eb31dfe6c60da16d1498f8cc3efac4dfa Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 18 Jan 2020 14:04:17 -0500 Subject: Bug 1355479 - Flatten attribute storage in the HTML parser to AutoTArray to avoid malloc. - Removes nsHtml5ReleasableAttributeName - Adds nsHtml5AttributeEntry.h - Makes nsHtml5HtmlAttributes no longer gentered. Tag UXP Issue #1344 --- parser/html/nsHtml5HtmlAttributes.cpp | 188 ++++++++++++++++------------------ 1 file changed, 90 insertions(+), 98 deletions(-) (limited to 'parser/html/nsHtml5HtmlAttributes.cpp') diff --git a/parser/html/nsHtml5HtmlAttributes.cpp b/parser/html/nsHtml5HtmlAttributes.cpp index 1460b5ca0..bdccd8145 100644 --- a/parser/html/nsHtml5HtmlAttributes.cpp +++ b/parser/html/nsHtml5HtmlAttributes.cpp @@ -23,11 +23,6 @@ * DEALINGS IN THE SOFTWARE. */ -/* - * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT. - * Please edit HtmlAttributes.java instead and regenerate. - */ - #define nsHtml5HtmlAttributes_cpp__ #include "nsIAtom.h" @@ -59,12 +54,8 @@ nsHtml5HtmlAttributes* nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES = nullptr; -nsHtml5HtmlAttributes::nsHtml5HtmlAttributes(int32_t mode) - : mode(mode), - length(0), - names(jArray::newJArray(8)), - values(jArray::newJArray(8)), - lines(jArray::newJArray(8)) +nsHtml5HtmlAttributes::nsHtml5HtmlAttributes(int32_t aMode) + : mMode(aMode) { MOZ_COUNT_CTOR(nsHtml5HtmlAttributes); } @@ -76,11 +67,13 @@ nsHtml5HtmlAttributes::~nsHtml5HtmlAttributes() clear(0); } -int32_t -nsHtml5HtmlAttributes::getIndex(nsHtml5AttributeName* name) +int32_t +nsHtml5HtmlAttributes::getIndex(nsHtml5AttributeName* aName) { - for (int32_t i = 0; i < length; i++) { - if (names[i] == name) { + for (size_t i = 0; i < mStorage.Length(); i++) { + if (mStorage[i].GetLocal(NS_HTML5ATTRIBUTE_NAME_HTML) == + aName->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML)) { + // It's release asserted elsewhere that i can't be too large. return i; } } @@ -88,9 +81,9 @@ nsHtml5HtmlAttributes::getIndex(nsHtml5AttributeName* name) } nsHtml5String -nsHtml5HtmlAttributes::getValue(nsHtml5AttributeName* name) +nsHtml5HtmlAttributes::getValue(nsHtml5AttributeName* aName) { - int32_t index = getIndex(name); + int32_t index = getIndex(aName); if (index == -1) { return nullptr; } else { @@ -101,106 +94,98 @@ nsHtml5HtmlAttributes::getValue(nsHtml5AttributeName* name) int32_t nsHtml5HtmlAttributes::getLength() { - return length; + return mStorage.Length(); } -nsIAtom* -nsHtml5HtmlAttributes::getLocalNameNoBoundsCheck(int32_t index) +nsIAtom* +nsHtml5HtmlAttributes::getLocalNameNoBoundsCheck(int32_t aIndex) { - MOZ_ASSERT(index < length && index >= 0, "Index out of bounds"); - return names[index]->getLocal(mode); + MOZ_ASSERT(aIndex < int32_t(mStorage.Length()) && aIndex >= 0, + "Index out of bounds"); + return mStorage[aIndex].GetLocal(mMode); } -int32_t -nsHtml5HtmlAttributes::getURINoBoundsCheck(int32_t index) +int32_t +nsHtml5HtmlAttributes::getURINoBoundsCheck(int32_t aIndex) { - MOZ_ASSERT(index < length && index >= 0, "Index out of bounds"); - return names[index]->getUri(mode); + MOZ_ASSERT(aIndex < int32_t(mStorage.Length()) && aIndex >= 0, + "Index out of bounds"); + return mStorage[aIndex].GetUri(mMode); } -nsIAtom* -nsHtml5HtmlAttributes::getPrefixNoBoundsCheck(int32_t index) +nsIAtom* +nsHtml5HtmlAttributes::getPrefixNoBoundsCheck(int32_t aIndex) { - MOZ_ASSERT(index < length && index >= 0, "Index out of bounds"); - return names[index]->getPrefix(mode); + MOZ_ASSERT(aIndex < int32_t(mStorage.Length()) && aIndex >= 0, + "Index out of bounds"); + return mStorage[aIndex].GetPrefix(mMode); } nsHtml5String -nsHtml5HtmlAttributes::getValueNoBoundsCheck(int32_t index) +nsHtml5HtmlAttributes::getValueNoBoundsCheck(int32_t aIndex) { - MOZ_ASSERT(index < length && index >= 0, "Index out of bounds"); - return values[index]; + MOZ_ASSERT(aIndex < int32_t(mStorage.Length()) && aIndex >= 0, + "Index out of bounds"); + return mStorage[aIndex].GetValue(); } -nsHtml5AttributeName* -nsHtml5HtmlAttributes::getAttributeNameNoBoundsCheck(int32_t index) +int32_t +nsHtml5HtmlAttributes::getLineNoBoundsCheck(int32_t aIndex) { - MOZ_ASSERT(index < length && index >= 0, "Index out of bounds"); - return names[index]; + MOZ_ASSERT(aIndex < int32_t(mStorage.Length()) && aIndex >= 0, + "Index out of bounds"); + return mStorage[aIndex].GetLine(); } -int32_t -nsHtml5HtmlAttributes::getLineNoBoundsCheck(int32_t index) +void +nsHtml5HtmlAttributes::addAttribute(nsHtml5AttributeName* aName, + nsHtml5String aValue, + int32_t aLine) { - MOZ_ASSERT(index < length && index >= 0, "Index out of bounds"); - return lines[index]; + mStorage.AppendElement(nsHtml5AttributeEntry(aName, aValue, aLine)); + MOZ_RELEASE_ASSERT(mStorage.Length() <= INT32_MAX, + "Can't handle this many attributes."); } -void -nsHtml5HtmlAttributes::addAttribute(nsHtml5AttributeName* name, nsHtml5String value, int32_t line) +// Isindex-only, so doesn't need to deal with SVG and MathML +void +nsHtml5HtmlAttributes::AddAttributeWithLocal(nsIAtom* aName, + nsHtml5String aValue, + int32_t aLine) { - if (names.length == length) { - int32_t newLen = length << 1; - jArray newNames = jArray::newJArray(newLen); - nsHtml5ArrayCopy::arraycopy(names, newNames, names.length); - names = newNames; - jArray newValues = jArray::newJArray(newLen); - nsHtml5ArrayCopy::arraycopy(values, newValues, values.length); - values = newValues; - jArray newLines = jArray::newJArray(newLen); - nsHtml5ArrayCopy::arraycopy(lines, newLines, lines.length); - lines = newLines; - } - names[length] = name; - values[length] = value; - lines[length] = line; - length++; + mStorage.AppendElement(nsHtml5AttributeEntry(aName, aValue, aLine)); + MOZ_RELEASE_ASSERT(mStorage.Length() <= INT32_MAX, + "Can't handle this many attributes."); } -void -nsHtml5HtmlAttributes::clear(int32_t m) +void +nsHtml5HtmlAttributes::clear(int32_t aMode) { - for (int32_t i = 0; i < length; i++) { - names[i]->release(); - names[i] = nullptr; - values[i].Release(); - values[i] = nullptr; + for (nsHtml5AttributeEntry& entry : mStorage) { + entry.ReleaseValue(); } - length = 0; - mode = m; + mStorage.TruncateLength(0); + mMode = aMode; } -void -nsHtml5HtmlAttributes::releaseValue(int32_t i) +void +nsHtml5HtmlAttributes::releaseValue(int32_t aIndex) { - values[i].Release(); + mStorage[aIndex].ReleaseValue(); } void nsHtml5HtmlAttributes::clearWithoutReleasingContents() { - for (int32_t i = 0; i < length; i++) { - names[i] = nullptr; - values[i] = nullptr; - } - length = 0; + mStorage.TruncateLength(0); } -bool -nsHtml5HtmlAttributes::contains(nsHtml5AttributeName* name) +bool +nsHtml5HtmlAttributes::contains(nsHtml5AttributeName* aName) { - for (int32_t i = 0; i < length; i++) { - if (name->equalsAnother(names[i])) { + for (size_t i = 0; i < mStorage.Length(); i++) { + if (mStorage[i].GetLocal(NS_HTML5ATTRIBUTE_NAME_HTML) == + aName->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML)) { return true; } } @@ -210,43 +195,44 @@ nsHtml5HtmlAttributes::contains(nsHtml5AttributeName* name) void nsHtml5HtmlAttributes::adjustForMath() { - mode = NS_HTML5ATTRIBUTE_NAME_MATHML; + mMode = NS_HTML5ATTRIBUTE_NAME_MATHML; } void nsHtml5HtmlAttributes::adjustForSvg() { - mode = NS_HTML5ATTRIBUTE_NAME_SVG; + mMode = NS_HTML5ATTRIBUTE_NAME_SVG; } -nsHtml5HtmlAttributes* -nsHtml5HtmlAttributes::cloneAttributes(nsHtml5AtomTable* interner) +nsHtml5HtmlAttributes* +nsHtml5HtmlAttributes::cloneAttributes(nsHtml5AtomTable* aInterner) { - MOZ_ASSERT((!length) || !mode || mode == 3); - nsHtml5HtmlAttributes* clone = new nsHtml5HtmlAttributes(0); - for (int32_t i = 0; i < length; i++) { - clone->addAttribute(names[i]->cloneAttributeName(interner), nsHtml5Portability::newStringFromString(values[i]), lines[i]); + MOZ_ASSERT(mStorage.IsEmpty() || !mMode); + nsHtml5HtmlAttributes* clone = + new nsHtml5HtmlAttributes(NS_HTML5ATTRIBUTE_NAME_HTML); + for (nsHtml5AttributeEntry& entry : mStorage) { + clone->AddEntry(entry.Clone(aInterner)); } return clone; } -bool -nsHtml5HtmlAttributes::equalsAnother(nsHtml5HtmlAttributes* other) +bool +nsHtml5HtmlAttributes::equalsAnother(nsHtml5HtmlAttributes* aOther) { - MOZ_ASSERT(!mode || mode == 3, "Trying to compare attributes in foreign content."); - int32_t otherLength = other->getLength(); - if (length != otherLength) { + MOZ_ASSERT(!mMode, "Trying to compare attributes in foreign content."); + if (mStorage.Length() != aOther->mStorage.Length()) { return false; } - for (int32_t i = 0; i < length; i++) { + for (nsHtml5AttributeEntry& entry : mStorage) { bool found = false; - nsIAtom* ownLocal = names[i]->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML); - for (int32_t j = 0; j < otherLength; j++) { - if (ownLocal == other->names[j]->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML)) { + nsIAtom* ownLocal = entry.GetLocal(NS_HTML5ATTRIBUTE_NAME_HTML); + for (nsHtml5AttributeEntry& otherEntry : aOther->mStorage) { + if (ownLocal == otherEntry.GetLocal(NS_HTML5ATTRIBUTE_NAME_HTML)) { found = true; - if (!nsHtml5Portability::stringEqualsString(values[i], other->values[j])) { + if (!entry.GetValue().Equals(otherEntry.GetValue())) { return false; } + break; } } if (!found) { @@ -256,6 +242,12 @@ nsHtml5HtmlAttributes::equalsAnother(nsHtml5HtmlAttributes* other) return true; } +void +nsHtml5HtmlAttributes::AddEntry(nsHtml5AttributeEntry&& aEntry) +{ + mStorage.AppendElement(aEntry); +} + void nsHtml5HtmlAttributes::initializeStatics() { -- cgit v1.2.3