Title: [208812] trunk/Source/WebCore
Revision
208812
Author
[email protected]
Date
2016-11-16 14:28:33 -0800 (Wed, 16 Nov 2016)

Log Message

Micro-optimize AtomicHTMLToken::initializeAttributes()
https://bugs.webkit.org/show_bug.cgi?id=164826

Reviewed by Sam Weinig.

Micro-optimize AtomicHTMLToken::initializeAttributes():
- Use uncheckedAppend() instead of append() since we reserve capacity
  before the loop.
- Use a more efficient findAttribute() that only checks the local names
  since this function only adds attributes that have to namespace or
  prefix.

No new tests, no Web-exposed behavior change.

* html/parser/AtomicHTMLToken.h:
(WebCore::hasAttribute):
(WebCore::AtomicHTMLToken::initializeAttributes):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (208811 => 208812)


--- trunk/Source/WebCore/ChangeLog	2016-11-16 22:24:45 UTC (rev 208811)
+++ trunk/Source/WebCore/ChangeLog	2016-11-16 22:28:33 UTC (rev 208812)
@@ -1,3 +1,23 @@
+2016-11-16  Chris Dumez  <[email protected]>
+
+        Micro-optimize AtomicHTMLToken::initializeAttributes()
+        https://bugs.webkit.org/show_bug.cgi?id=164826
+
+        Reviewed by Sam Weinig.
+
+        Micro-optimize AtomicHTMLToken::initializeAttributes():
+        - Use uncheckedAppend() instead of append() since we reserve capacity
+          before the loop.
+        - Use a more efficient findAttribute() that only checks the local names
+          since this function only adds attributes that have to namespace or
+          prefix.
+
+        No new tests, no Web-exposed behavior change.
+
+        * html/parser/AtomicHTMLToken.h:
+        (WebCore::hasAttribute):
+        (WebCore::AtomicHTMLToken::initializeAttributes):
+
 2016-11-16  Beth Dakin  <[email protected]>
 
         Another build fix.

Modified: trunk/Source/WebCore/html/parser/AtomicHTMLToken.h (208811 => 208812)


--- trunk/Source/WebCore/html/parser/AtomicHTMLToken.h	2016-11-16 22:24:45 UTC (rev 208811)
+++ trunk/Source/WebCore/html/parser/AtomicHTMLToken.h	2016-11-16 22:28:33 UTC (rev 208812)
@@ -92,6 +92,7 @@
 };
 
 const Attribute* findAttribute(const Vector<Attribute>&, const QualifiedName&);
+bool hasAttribute(const Vector<Attribute>&, const AtomicString& localName);
 
 inline HTMLToken::Type AtomicHTMLToken::type() const
 {
@@ -181,6 +182,15 @@
     return nullptr;
 }
 
+inline bool hasAttribute(const Vector<Attribute>& attributes, const AtomicString& localName)
+{
+    for (auto& attribute : attributes) {
+        if (attribute.localName() == localName)
+            return true;
+    }
+    return false;
+}
+
 inline void AtomicHTMLToken::initializeAttributes(const HTMLToken::AttributeList& attributes)
 {
     unsigned size = attributes.size();
@@ -192,11 +202,11 @@
         if (attribute.name.isEmpty())
             continue;
 
-        QualifiedName name(nullAtom, AtomicString(attribute.name), nullAtom);
+        AtomicString localName(attribute.name);
 
         // FIXME: This is N^2 for the number of attributes.
-        if (!findAttribute(m_attributes, name))
-            m_attributes.append(Attribute(name, AtomicString(attribute.value)));
+        if (!hasAttribute(m_attributes, localName))
+            m_attributes.uncheckedAppend(Attribute(QualifiedName(nullAtom, localName, nullAtom), AtomicString(attribute.value)));
     }
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to