Title: [165045] trunk/Source/WebCore
Revision
165045
Author
[email protected]
Date
2014-03-04 02:28:38 -0800 (Tue, 04 Mar 2014)

Log Message

Remove Document::idAttributeName().
<https://webkit.org/b/129663>

Reviewed by Ryosuke "DYEB" Niwa.

This abstraction is not actually used and causes unnecessary indirection
in some pretty hot code paths.

Replace it with hard-coded HTMLNames::idAttr instead which is a compile
time constant pointer. We can revisit this in the future if we wish to
implement support for custom id attributes.

* dom/Attr.cpp:
(WebCore::Attr::isId):
* dom/Document.cpp:
(WebCore::Document::Document):
* dom/Document.h:
* dom/Element.cpp:
(WebCore::Element::attributeChanged):
(WebCore::Element::willModifyAttribute):
* dom/Element.h:
(WebCore::Element::getIdAttribute):
(WebCore::Element::getNameAttribute):
(WebCore::Element::setIdAttribute):
* html/HTMLElement.cpp:
(WebCore::HTMLElement::parseAttribute):
* html/HTMLFrameElementBase.cpp:
(WebCore::HTMLFrameElementBase::parseAttribute):
* html/HTMLMapElement.cpp:
(WebCore::HTMLMapElement::parseAttribute):
* svg/SVGElement.cpp:
(WebCore::SVGElement::attributeChanged):
(WebCore::SVGElement::isKnownAttribute):
(WebCore::SVGElement::svgAttributeChanged):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (165044 => 165045)


--- trunk/Source/WebCore/ChangeLog	2014-03-04 09:45:55 UTC (rev 165044)
+++ trunk/Source/WebCore/ChangeLog	2014-03-04 10:28:38 UTC (rev 165045)
@@ -1,3 +1,40 @@
+2014-03-04  Andreas Kling  <[email protected]>
+
+        Remove Document::idAttributeName().
+        <https://webkit.org/b/129663>
+
+        Reviewed by Ryosuke "DYEB" Niwa.
+
+        This abstraction is not actually used and causes unnecessary indirection
+        in some pretty hot code paths.
+
+        Replace it with hard-coded HTMLNames::idAttr instead which is a compile
+        time constant pointer. We can revisit this in the future if we wish to
+        implement support for custom id attributes.
+
+        * dom/Attr.cpp:
+        (WebCore::Attr::isId):
+        * dom/Document.cpp:
+        (WebCore::Document::Document):
+        * dom/Document.h:
+        * dom/Element.cpp:
+        (WebCore::Element::attributeChanged):
+        (WebCore::Element::willModifyAttribute):
+        * dom/Element.h:
+        (WebCore::Element::getIdAttribute):
+        (WebCore::Element::getNameAttribute):
+        (WebCore::Element::setIdAttribute):
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::parseAttribute):
+        * html/HTMLFrameElementBase.cpp:
+        (WebCore::HTMLFrameElementBase::parseAttribute):
+        * html/HTMLMapElement.cpp:
+        (WebCore::HTMLMapElement::parseAttribute):
+        * svg/SVGElement.cpp:
+        (WebCore::SVGElement::attributeChanged):
+        (WebCore::SVGElement::isKnownAttribute):
+        (WebCore::SVGElement::svgAttributeChanged):
+
 2014-03-04  Ryosuke Niwa  <[email protected]>
 
         REGRESSION(r164856): Use after free in WebCore::QualifiedName::operator== / WebCore::StyledElement::attributeChanged

Modified: trunk/Source/WebCore/dom/Attr.cpp (165044 => 165045)


--- trunk/Source/WebCore/dom/Attr.cpp	2014-03-04 09:45:55 UTC (rev 165044)
+++ trunk/Source/WebCore/dom/Attr.cpp	2014-03-04 10:28:38 UTC (rev 165045)
@@ -182,7 +182,7 @@
 
 bool Attr::isId() const
 {
-    return qualifiedName().matches(document().idAttributeName());
+    return qualifiedName().matches(HTMLNames::idAttr);
 }
 
 CSSStyleDeclaration* Attr::style()

Modified: trunk/Source/WebCore/dom/Document.cpp (165044 => 165045)


--- trunk/Source/WebCore/dom/Document.cpp	2014-03-04 09:45:55 UTC (rev 165044)
+++ trunk/Source/WebCore/dom/Document.cpp	2014-03-04 10:28:38 UTC (rev 165045)
@@ -468,7 +468,6 @@
     , m_isSrcdocDocument(false)
     , m_eventQueue(*this)
     , m_weakFactory(this)
-    , m_idAttributeName(idAttr)
 #if ENABLE(FULLSCREEN_API)
     , m_areKeysEnabledInFullScreen(0)
     , m_fullScreenRenderer(nullptr)

Modified: trunk/Source/WebCore/dom/Document.h (165044 => 165045)


--- trunk/Source/WebCore/dom/Document.h	2014-03-04 09:45:55 UTC (rev 165044)
+++ trunk/Source/WebCore/dom/Document.h	2014-03-04 10:28:38 UTC (rev 165045)
@@ -1108,8 +1108,6 @@
     void removeMediaCanStartListener(MediaCanStartListener*);
     MediaCanStartListener* takeAnyMediaCanStartListener();
 
-    const QualifiedName& idAttributeName() const { return m_idAttributeName; }
-    
 #if ENABLE(FULLSCREEN_API)
     bool webkitIsFullScreen() const { return m_fullScreenElement.get(); }
     bool webkitFullScreenKeyboardInputAllowed() const { return m_fullScreenElement.get() && m_areKeysEnabledInFullScreen; }
@@ -1559,8 +1557,6 @@
 
     HashSet<MediaCanStartListener*> m_mediaCanStartListeners;
 
-    QualifiedName m_idAttributeName;
-
 #if ENABLE(FULLSCREEN_API)
     bool m_areKeysEnabledInFullScreen;
     RefPtr<Element> m_fullScreenElement;

Modified: trunk/Source/WebCore/dom/Element.cpp (165044 => 165045)


--- trunk/Source/WebCore/dom/Element.cpp	2014-03-04 09:45:55 UTC (rev 165044)
+++ trunk/Source/WebCore/dom/Element.cpp	2014-03-04 10:28:38 UTC (rev 165045)
@@ -1078,7 +1078,7 @@
     bool testShouldInvalidateStyle = inRenderedDocument() && styleResolver && styleChangeType() < FullStyleChange;
     bool shouldInvalidateStyle = false;
 
-    if (isIdAttributeName(name)) {
+    if (name == HTMLNames::idAttr) {
         AtomicString oldId = elementData()->idForStyleResolution();
         AtomicString newId = makeIdForStyleResolution(newValue, document().inQuirksMode());
         if (newId != oldId) {
@@ -2745,7 +2745,7 @@
 
 void Element::willModifyAttribute(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue)
 {
-    if (isIdAttributeName(name))
+    if (name == HTMLNames::idAttr)
         updateId(oldValue, newValue);
     else if (name == HTMLNames::nameAttr)
         updateName(oldValue, newValue);

Modified: trunk/Source/WebCore/dom/Element.h (165044 => 165045)


--- trunk/Source/WebCore/dom/Element.h	2014-03-04 09:45:55 UTC (rev 165044)
+++ trunk/Source/WebCore/dom/Element.h	2014-03-04 10:28:38 UTC (rev 165045)
@@ -179,7 +179,6 @@
     static bool parseAttributeName(QualifiedName&, const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionCode&);
     void setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionCode&);
 
-    bool isIdAttributeName(const QualifiedName&) const;
     const AtomicString& getIdAttribute() const;
     void setIdAttribute(const AtomicString&);
 
@@ -742,28 +741,23 @@
     return elementData()->idForStyleResolution();
 }
 
-inline bool Element::isIdAttributeName(const QualifiedName& attributeName) const
-{
-    // FIXME: This check is probably not correct for the case where the document has an id attribute
-    // with a non-null namespace, because it will return false, a false negative, if the prefixes
-    // don't match but the local name and namespace both do. However, since this has been like this
-    // for a while and the code paths may be hot, we'll have to measure performance if we fix it.
-    return attributeName == document().idAttributeName();
-}
-
 inline const AtomicString& Element::getIdAttribute() const
 {
-    return hasID() ? fastGetAttribute(document().idAttributeName()) : nullAtom;
+    if (hasID())
+        return elementData()->findAttributeByName(HTMLNames::idAttr)->value();
+    return nullAtom;
 }
 
 inline const AtomicString& Element::getNameAttribute() const
 {
-    return hasName() ? fastGetAttribute(HTMLNames::nameAttr) : nullAtom;
+    if (hasName())
+        return elementData()->findAttributeByName(HTMLNames::nameAttr)->value();
+    return nullAtom;
 }
 
 inline void Element::setIdAttribute(const AtomicString& value)
 {
-    setAttribute(document().idAttributeName(), value);
+    setAttribute(HTMLNames::idAttr, value);
 }
 
 inline const SpaceSplitString& Element::classNames() const

Modified: trunk/Source/WebCore/html/HTMLElement.cpp (165044 => 165045)


--- trunk/Source/WebCore/html/HTMLElement.cpp	2014-03-04 09:45:55 UTC (rev 165044)
+++ trunk/Source/WebCore/html/HTMLElement.cpp	2014-03-04 10:28:38 UTC (rev 165045)
@@ -338,7 +338,7 @@
 
 void HTMLElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
 {
-    if (isIdAttributeName(name) || name == classAttr || name == styleAttr)
+    if (name == HTMLNames::idAttr || name == HTMLNames::classAttr || name == HTMLNames::styleAttr)
         return StyledElement::parseAttribute(name, value);
 
     if (name == dirAttr)

Modified: trunk/Source/WebCore/html/HTMLFrameElementBase.cpp (165044 => 165045)


--- trunk/Source/WebCore/html/HTMLFrameElementBase.cpp	2014-03-04 09:45:55 UTC (rev 165044)
+++ trunk/Source/WebCore/html/HTMLFrameElementBase.cpp	2014-03-04 10:28:38 UTC (rev 165045)
@@ -94,8 +94,7 @@
         setLocation("about:srcdoc");
     else if (name == srcAttr && !fastHasAttribute(srcdocAttr))
         setLocation(stripLeadingAndTrailingHTMLSpaces(value));
-    else if (isIdAttributeName(name)) {
-        // Important to call through to base for the id attribute so the hasID bit gets set.
+    else if (name == HTMLNames::idAttr) {
         HTMLFrameOwnerElement::parseAttribute(name, value);
         m_frameName = value;
     } else if (name == nameAttr) {

Modified: trunk/Source/WebCore/html/HTMLMapElement.cpp (165044 => 165045)


--- trunk/Source/WebCore/html/HTMLMapElement.cpp	2014-03-04 09:45:55 UTC (rev 165044)
+++ trunk/Source/WebCore/html/HTMLMapElement.cpp	2014-03-04 10:28:38 UTC (rev 165045)
@@ -88,8 +88,8 @@
     // FIXME: This logic seems wrong for XML documents.
     // Either the id or name will be used depending on the order the attributes are parsed.
 
-    if (isIdAttributeName(name) || name == nameAttr) {
-        if (isIdAttributeName(name)) {
+    if (name == HTMLNames::idAttr || name == HTMLNames::nameAttr) {
+        if (name == HTMLNames::idAttr) {
             // Call base class so that hasID bit gets set.
             HTMLElement::parseAttribute(name, value);
             if (document().isHTMLDocument())

Modified: trunk/Source/WebCore/svg/SVGElement.cpp (165044 => 165045)


--- trunk/Source/WebCore/svg/SVGElement.cpp	2014-03-04 09:45:55 UTC (rev 165044)
+++ trunk/Source/WebCore/svg/SVGElement.cpp	2014-03-04 10:28:38 UTC (rev 165045)
@@ -720,7 +720,7 @@
 {
     StyledElement::attributeChanged(name, oldValue, newValue);
 
-    if (isIdAttributeName(name))
+    if (name == HTMLNames::idAttr)
         document().accessSVGExtensions()->rebuildAllElementReferencesForTarget(this);
 
     // Changes to the style attribute are processed lazily (see Element::getAttribute() and related methods),
@@ -1014,7 +1014,7 @@
 
 bool SVGElement::isKnownAttribute(const QualifiedName& attrName)
 {
-    return isIdAttributeName(attrName);
+    return attrName == HTMLNames::idAttr;
 }
 
 void SVGElement::svgAttributeChanged(const QualifiedName& attrName)
@@ -1031,7 +1031,7 @@
         return;
     }
 
-    if (isIdAttributeName(attrName)) {
+    if (attrName == HTMLNames::idAttr) {
         auto renderer = this->renderer();
         // Notify resources about id changes, this is important as we cache resources by id in SVGDocumentExtensions
         if (renderer && renderer->isSVGResourceContainer())
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to