Title: [108449] trunk/Source/WebCore
Revision
108449
Author
[email protected]
Date
2012-02-21 23:20:19 -0800 (Tue, 21 Feb 2012)

Log Message

HasIDFlag and HasClassFlag can be removed.
https://bugs.webkit.org/show_bug.cgi?id=77861

Reviewed by Andreas Kling.

Replaced HasIDFlag and HasClassFlag with a check against
ElementAttributeData. It looks these flags (originally bitfields)
were legacy of ancient era, where we didn't cache @id and @class
values and needed a hash lookup for each check.

No new tests. No behavioral change.

* dom/Element.cpp:
(WebCore::Element::idAttributeChanged):
* dom/Element.h:
(WebCore::Element::hasID):
(WebCore):
(WebCore::Element::hasClass):
(WebCore::Node::hasID):
(WebCore::Node::hasClass):
* dom/ElementAttributeData.h:
(WebCore::ElementAttributeData::hasID):
(WebCore::ElementAttributeData::hasClass):
(ElementAttributeData):
* dom/Node.h:
(Node):
(WebCore::nodeStyleChangeShift):
* dom/StyledElement.cpp:
(WebCore::StyledElement::classAttributeChanged):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (108448 => 108449)


--- trunk/Source/WebCore/ChangeLog	2012-02-22 07:15:46 UTC (rev 108448)
+++ trunk/Source/WebCore/ChangeLog	2012-02-22 07:20:19 UTC (rev 108449)
@@ -1,3 +1,35 @@
+2012-02-21  MORITA Hajime  <[email protected]>
+
+        HasIDFlag and HasClassFlag can be removed.
+        https://bugs.webkit.org/show_bug.cgi?id=77861
+
+        Reviewed by Andreas Kling.
+
+        Replaced HasIDFlag and HasClassFlag with a check against
+        ElementAttributeData. It looks these flags (originally bitfields)
+        were legacy of ancient era, where we didn't cache @id and @class
+        values and needed a hash lookup for each check.
+
+        No new tests. No behavioral change.
+
+        * dom/Element.cpp:
+        (WebCore::Element::idAttributeChanged):
+        * dom/Element.h:
+        (WebCore::Element::hasID):
+        (WebCore):
+        (WebCore::Element::hasClass):
+        (WebCore::Node::hasID):
+        (WebCore::Node::hasClass):
+        * dom/ElementAttributeData.h:
+        (WebCore::ElementAttributeData::hasID):
+        (WebCore::ElementAttributeData::hasClass):
+        (ElementAttributeData):
+        * dom/Node.h:
+        (Node):
+        (WebCore::nodeStyleChangeShift):
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::classAttributeChanged):
+
 2012-02-21  Matthew Delaney  <[email protected]>
 
         2D Canvas setTransform makes unnecessary matrix mults

Modified: trunk/Source/WebCore/dom/Element.cpp (108448 => 108449)


--- trunk/Source/WebCore/dom/Element.cpp	2012-02-22 07:15:46 UTC (rev 108448)
+++ trunk/Source/WebCore/dom/Element.cpp	2012-02-22 07:20:19 UTC (rev 108449)
@@ -697,7 +697,6 @@
 
 void Element::idAttributeChanged(Attribute* attr)
 {
-    setHasID(!attr->isNull());
     if (attributeData()) {
         if (attr->isNull())
             attributeData()->setIdForStyleResolution(nullAtom);

Modified: trunk/Source/WebCore/dom/Element.h (108448 => 108449)


--- trunk/Source/WebCore/dom/Element.h	2012-02-22 07:15:46 UTC (rev 108448)
+++ trunk/Source/WebCore/dom/Element.h	2012-02-22 07:20:19 UTC (rev 108449)
@@ -394,6 +394,9 @@
 
     const AtomicString& webkitRegionOverflow() const;
 
+    bool hasID() const;
+    bool hasClass() const;
+
 protected:
     Element(const QualifiedName& tagName, Document* document, ConstructionType type)
         : ContainerNode(document, type)
@@ -697,6 +700,27 @@
     return static_cast<Element*>(child);
 }
 
+inline bool Element::hasID() const
+{
+    return attributeData() && attributeData()->hasID();
+}
+
+inline bool Element::hasClass() const
+{
+    return attributeData() && attributeData()->hasClass();
+}
+
+// Put here to make them inline.
+inline bool Node::hasID() const
+{
+    return isElementNode() && toElement(this)->hasID();
+}
+
+inline bool Node::hasClass() const
+{
+    return isElementNode() && toElement(this)->hasClass();
+}
+
 } // namespace
 
 #endif

Modified: trunk/Source/WebCore/dom/ElementAttributeData.h (108448 => 108449)


--- trunk/Source/WebCore/dom/ElementAttributeData.h	2012-02-22 07:15:46 UTC (rev 108448)
+++ trunk/Source/WebCore/dom/ElementAttributeData.h	2012-02-22 07:20:19 UTC (rev 108449)
@@ -66,6 +66,9 @@
     void removeAttribute(const QualifiedName&, Element*);
     void removeAttribute(size_t index, Element*);
 
+    bool hasID() const { return !m_idForStyleResolution.isNull(); }
+    bool hasClass() const { return !m_classNames.isNull(); }
+
 private:
     friend class Element;
     friend class NamedNodeMap;

Modified: trunk/Source/WebCore/dom/Node.h (108448 => 108449)


--- trunk/Source/WebCore/dom/Node.h	2012-02-22 07:15:46 UTC (rev 108448)
+++ trunk/Source/WebCore/dom/Node.h	2012-02-22 07:20:19 UTC (rev 108449)
@@ -90,7 +90,7 @@
 
 typedef int ExceptionCode;
 
-const int nodeStyleChangeShift = 25;
+const int nodeStyleChangeShift = 23;
 
 // SyntheticStyleChange means that we need to go through the entire style change logic even though
 // no style property has actually changed. It is used to restructure the tree when, for instance,
@@ -301,8 +301,9 @@
 
     bool attributeStyleDirty() const { return getFlag(AttributeStyleDirtyFlag); }
     bool hasName() const { return getFlag(HasNameFlag); }
-    bool hasID() const { return getFlag(HasIDFlag); }
-    bool hasClass() const { return getFlag(HasClassFlag); }
+    bool hasID() const;
+    bool hasClass() const;
+    
     bool active() const { return getFlag(IsActiveFlag); }
     bool inActiveChain() const { return getFlag(InActiveChainFlag); }
     bool inDetach() const { return getFlag(InDetachFlag); }
@@ -319,8 +320,6 @@
     void clearAttributeStyleDirty() { clearFlag(AttributeStyleDirtyFlag); }
 
     void setHasName(bool f) { setFlag(f, HasNameFlag); }
-    void setHasID(bool f) { setFlag(f, HasIDFlag); }
-    void setHasClass(bool f) { setFlag(f, HasClassFlag); }
     void setChildNeedsStyleRecalc() { setFlag(ChildNeedsStyleRecalcFlag); }
     void clearChildNeedsStyleRecalc() { clearFlag(ChildNeedsStyleRecalcFlag); }
     void setInDocument() { setFlag(InDocumentFlag); }
@@ -654,37 +653,35 @@
         IsStyledElementFlag = 1 << 4,
         IsHTMLFlag = 1 << 5,
         IsSVGFlag = 1 << 6,
-        HasIDFlag = 1 << 7,
-        HasClassFlag = 1 << 8,
-        IsAttachedFlag = 1 << 9,
-        ChildNeedsStyleRecalcFlag = 1 << 10,
-        InDocumentFlag = 1 << 11,
-        IsLinkFlag = 1 << 12,
-        IsActiveFlag = 1 << 13,
-        IsHoveredFlag = 1 << 14,
-        InActiveChainFlag = 1 << 15,
-        InDetachFlag = 1 << 16,
-        HasRareDataFlag = 1 << 17,
-        IsShadowRootOrSVGShadowRootFlag = 1 << 18,
+        IsAttachedFlag = 1 << 7,
+        ChildNeedsStyleRecalcFlag = 1 << 8,
+        InDocumentFlag = 1 << 9,
+        IsLinkFlag = 1 << 10,
+        IsActiveFlag = 1 << 11,
+        IsHoveredFlag = 1 << 12,
+        InActiveChainFlag = 1 << 13,
+        InDetachFlag = 1 << 14,
+        HasRareDataFlag = 1 << 15,
+        IsShadowRootOrSVGShadowRootFlag = 1 << 16,
 
         // These bits are used by derived classes, pulled up here so they can
         // be stored in the same memory word as the Node bits above.
-        IsParsingChildrenFinishedFlag = 1 << 19, // Element
-        IsStyleAttributeValidFlag = 1 << 20, // StyledElement
-        IsSynchronizingStyleAttributeFlag = 1 << 21, // StyledElement
+        IsParsingChildrenFinishedFlag = 1 << 17, // Element
+        IsStyleAttributeValidFlag = 1 << 18, // StyledElement
+        IsSynchronizingStyleAttributeFlag = 1 << 19, // StyledElement
 #if ENABLE(SVG)
-        AreSVGAttributesValidFlag = 1 << 22, // Element
-        IsSynchronizingSVGAttributesFlag = 1 << 23, // SVGElement
-        HasSVGRareDataFlag = 1 << 24, // SVGElement
+        AreSVGAttributesValidFlag = 1 << 20, // Element
+        IsSynchronizingSVGAttributesFlag = 1 << 21, // SVGElement
+        HasSVGRareDataFlag = 1 << 22, // SVGElement
 #endif
 
         StyleChangeMask = 1 << nodeStyleChangeShift | 1 << (nodeStyleChangeShift + 1),
 
-        SelfOrAncestorHasDirAutoFlag = 1 << 27,
-        HasCustomWillOrDidRecalcStyleFlag = 1 << 28,
-        HasCustomStyleForRendererFlag = 1 << 29,
+        SelfOrAncestorHasDirAutoFlag = 1 << 25,
+        HasCustomWillOrDidRecalcStyleFlag = 1 << 26,
+        HasCustomStyleForRendererFlag = 1 << 27,
 
-        HasNameFlag = 1 << 30,
+        HasNameFlag = 1 << 28,
 
         AttributeStyleDirtyFlag = 1 << 31,
 
@@ -695,7 +692,7 @@
 #endif
     };
 
-    // 1 bit remaining
+    // 3 bits remaining
 
     bool getFlag(NodeFlags mask) const { return m_nodeFlags & mask; }
     void setFlag(bool f, NodeFlags mask) const { m_nodeFlags = (m_nodeFlags & ~mask) | (-(int32_t)f & mask); } 

Modified: trunk/Source/WebCore/dom/StyledElement.cpp (108448 => 108449)


--- trunk/Source/WebCore/dom/StyledElement.cpp	2012-02-22 07:15:46 UTC (rev 108448)
+++ trunk/Source/WebCore/dom/StyledElement.cpp	2012-02-22 07:20:19 UTC (rev 108449)
@@ -84,7 +84,6 @@
             break;
     }
     bool hasClass = i < length;
-    setHasClass(hasClass);
     if (hasClass) {
         const bool shouldFoldCase = document()->inQuirksMode();
         ensureAttributeData()->setClass(newClassString, shouldFoldCase);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to