Title: [292337] branches/safari-613-branch/Source/WebCore/html/parser/AtomHTMLToken.h
- Revision
- 292337
- Author
- alanc...@apple.com
- Date
- 2022-04-04 14:56:07 -0700 (Mon, 04 Apr 2022)
Log Message
Cherry-pick r291508. rdar://91259284
Optimize AtomHTMLToken::initializeAttributes()
https://bugs.webkit.org/show_bug.cgi?id=238074
Reviewed by Geoffrey Garen.
Use a HashSet to find duplicate attributes instead of doing a linear search.
This is a confirmed 1.2% progression on Speedometer on iMac20,1 via A/B bots.
html/parser/AtomHTMLToken.h:
(WebCore::AtomHTMLToken::initializeAttributes):
Modified Paths
Diff
Modified: branches/safari-613-branch/Source/WebCore/html/parser/AtomHTMLToken.h (292336 => 292337)
--- branches/safari-613-branch/Source/WebCore/html/parser/AtomHTMLToken.h 2022-04-04 21:56:05 UTC (rev 292336)
+++ branches/safari-613-branch/Source/WebCore/html/parser/AtomHTMLToken.h 2022-04-04 21:56:07 UTC (rev 292337)
@@ -204,6 +204,8 @@
if (!size)
return;
+ HashSet<AtomString> addedAttributes;
+ addedAttributes.reserveInitialCapacity(size);
m_attributes.reserveInitialCapacity(size);
for (auto& attribute : attributes) {
if (attribute.name.isEmpty())
@@ -211,8 +213,7 @@
auto qualifiedName = HTMLNameCache::makeAttributeQualifiedName(attribute.name);
- // FIXME: This is N^2 for the number of attributes.
- if (!hasAttribute(m_attributes, qualifiedName.localName()))
+ if (addedAttributes.add(qualifiedName.localName()).isNewEntry)
m_attributes.uncheckedAppend(Attribute(WTFMove(qualifiedName), HTMLNameCache::makeAttributeValue(attribute.value)));
else
m_hasDuplicateAttribute = HasDuplicateAttribute::Yes;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes