Title: [164654] trunk/Source/WebCore
Revision
164654
Author
[email protected]
Date
2014-02-25 09:57:31 -0800 (Tue, 25 Feb 2014)

Log Message

Tighten bitfields in live NodeLists and HTMLCollections
https://bugs.webkit.org/show_bug.cgi?id=129300

Reviewed by Geoffrey Garen.

Reduce the number of bits used for m_rootType and m_type in LiveNodeList.
Also use enum class for LiveNodeList types. We keep "Type" suffix not to
confuse old-ish compilers.

* dom/ClassNodeList.cpp:
(WebCore::ClassNodeList::ClassNodeList):
* dom/ContainerNode.cpp:
(WebCore::ContainerNode::getElementsByTagName):
(WebCore::ContainerNode::getElementsByName):
(WebCore::ContainerNode::getElementsByClassName):
(WebCore::ContainerNode::radioNodeList):
* dom/LiveNodeList.cpp:
(WebCore::LiveNodeList::collectionFirst):
(WebCore::LiveNodeList::collectionTraverseForward):
* dom/LiveNodeList.h:
(WebCore::LiveNodeList::LiveNodeList):
* dom/NameNodeList.cpp:
(WebCore::NameNodeList::NameNodeList):
* dom/NameNodeList.h:
(WebCore::NameNodeList::create):
* dom/NodeRareData.h:
(WebCore::NodeListsNodeData::namedNodeListKey):
* dom/TagNodeList.cpp:
(WebCore::HTMLTagNodeList::HTMLTagNodeList):
* dom/TagNodeList.h:
(WebCore::TagNodeList::create):
(WebCore::HTMLTagNodeList::create):
* html/HTMLCollection.h:
* html/LabelableElement.cpp:
(WebCore::LabelableElement::labels):
* html/LabelsNodeList.cpp:
(WebCore::LabelsNodeList::LabelsNodeList):
* html/LabelsNodeList.h:
* html/RadioNodeList.cpp:
(WebCore::RadioNodeList::RadioNodeList):
* html/RadioNodeList.h:
(WebCore::RadioNodeList::create):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (164653 => 164654)


--- trunk/Source/WebCore/ChangeLog	2014-02-25 17:53:33 UTC (rev 164653)
+++ trunk/Source/WebCore/ChangeLog	2014-02-25 17:57:31 UTC (rev 164654)
@@ -1,3 +1,48 @@
+2014-02-25  Ryosuke Niwa  <[email protected]>
+
+        Tighten bitfields in live NodeLists and HTMLCollections
+        https://bugs.webkit.org/show_bug.cgi?id=129300
+
+        Reviewed by Geoffrey Garen.
+
+        Reduce the number of bits used for m_rootType and m_type in LiveNodeList.
+        Also use enum class for LiveNodeList types. We keep "Type" suffix not to
+        confuse old-ish compilers.
+
+        * dom/ClassNodeList.cpp:
+        (WebCore::ClassNodeList::ClassNodeList):
+        * dom/ContainerNode.cpp:
+        (WebCore::ContainerNode::getElementsByTagName):
+        (WebCore::ContainerNode::getElementsByName):
+        (WebCore::ContainerNode::getElementsByClassName):
+        (WebCore::ContainerNode::radioNodeList):
+        * dom/LiveNodeList.cpp:
+        (WebCore::LiveNodeList::collectionFirst):
+        (WebCore::LiveNodeList::collectionTraverseForward):
+        * dom/LiveNodeList.h:
+        (WebCore::LiveNodeList::LiveNodeList):
+        * dom/NameNodeList.cpp:
+        (WebCore::NameNodeList::NameNodeList):
+        * dom/NameNodeList.h:
+        (WebCore::NameNodeList::create):
+        * dom/NodeRareData.h:
+        (WebCore::NodeListsNodeData::namedNodeListKey):
+        * dom/TagNodeList.cpp:
+        (WebCore::HTMLTagNodeList::HTMLTagNodeList):
+        * dom/TagNodeList.h:
+        (WebCore::TagNodeList::create):
+        (WebCore::HTMLTagNodeList::create):
+        * html/HTMLCollection.h:
+        * html/LabelableElement.cpp:
+        (WebCore::LabelableElement::labels):
+        * html/LabelsNodeList.cpp:
+        (WebCore::LabelsNodeList::LabelsNodeList):
+        * html/LabelsNodeList.h:
+        * html/RadioNodeList.cpp:
+        (WebCore::RadioNodeList::RadioNodeList):
+        * html/RadioNodeList.h:
+        (WebCore::RadioNodeList::create):
+
 2014-02-24  Anders Carlsson  <[email protected]>
 
         Make it possible to set the visited link provider on a per page basis

Modified: trunk/Source/WebCore/dom/ClassNodeList.cpp (164653 => 164654)


--- trunk/Source/WebCore/dom/ClassNodeList.cpp	2014-02-25 17:53:33 UTC (rev 164653)
+++ trunk/Source/WebCore/dom/ClassNodeList.cpp	2014-02-25 17:57:31 UTC (rev 164654)
@@ -36,7 +36,7 @@
 namespace WebCore {
 
 ClassNodeList::ClassNodeList(ContainerNode& rootNode, const String& classNames)
-    : LiveNodeList(rootNode, ClassNodeListType, InvalidateOnClassAttrChange)
+    : LiveNodeList(rootNode, Type::ClassNodeListType, InvalidateOnClassAttrChange)
     , m_classNames(classNames, document().inQuirksMode())
     , m_originalClassNames(classNames)
 {

Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (164653 => 164654)


--- trunk/Source/WebCore/dom/ContainerNode.cpp	2014-02-25 17:53:33 UTC (rev 164653)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp	2014-02-25 17:57:31 UTC (rev 164654)
@@ -1103,8 +1103,8 @@
         return 0;
 
     if (document().isHTMLDocument())
-        return ensureRareData().ensureNodeLists().addCacheWithAtomicName<HTMLTagNodeList>(*this, LiveNodeList::HTMLTagNodeListType, localName);
-    return ensureRareData().ensureNodeLists().addCacheWithAtomicName<TagNodeList>(*this, LiveNodeList::TagNodeListType, localName);
+        return ensureRareData().ensureNodeLists().addCacheWithAtomicName<HTMLTagNodeList>(*this, LiveNodeList::Type::HTMLTagNodeListType, localName);
+    return ensureRareData().ensureNodeLists().addCacheWithAtomicName<TagNodeList>(*this, LiveNodeList::Type::TagNodeListType, localName);
 }
 
 PassRefPtr<NodeList> ContainerNode::getElementsByTagNameNS(const AtomicString& namespaceURI, const AtomicString& localName)
@@ -1120,18 +1120,18 @@
 
 PassRefPtr<NodeList> ContainerNode::getElementsByName(const String& elementName)
 {
-    return ensureRareData().ensureNodeLists().addCacheWithAtomicName<NameNodeList>(*this, LiveNodeList::NameNodeListType, elementName);
+    return ensureRareData().ensureNodeLists().addCacheWithAtomicName<NameNodeList>(*this, LiveNodeList::Type::NameNodeListType, elementName);
 }
 
 PassRefPtr<NodeList> ContainerNode::getElementsByClassName(const String& classNames)
 {
-    return ensureRareData().ensureNodeLists().addCacheWithName<ClassNodeList>(*this, LiveNodeList::ClassNodeListType, classNames);
+    return ensureRareData().ensureNodeLists().addCacheWithName<ClassNodeList>(*this, LiveNodeList::Type::ClassNodeListType, classNames);
 }
 
 PassRefPtr<RadioNodeList> ContainerNode::radioNodeList(const AtomicString& name)
 {
     ASSERT(hasTagName(HTMLNames::formTag) || hasTagName(HTMLNames::fieldsetTag));
-    return ensureRareData().ensureNodeLists().addCacheWithAtomicName<RadioNodeList>(*this, LiveNodeList::RadioNodeListType, name);
+    return ensureRareData().ensureNodeLists().addCacheWithAtomicName<RadioNodeList>(*this, LiveNodeList::Type::RadioNodeListType, name);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/LiveNodeList.cpp (164653 => 164654)


--- trunk/Source/WebCore/dom/LiveNodeList.cpp	2014-02-25 17:53:33 UTC (rev 164653)
+++ trunk/Source/WebCore/dom/LiveNodeList.cpp	2014-02-25 17:57:31 UTC (rev 164654)
@@ -100,9 +100,9 @@
 Element* LiveNodeList::collectionFirst() const
 {
     auto& root = rootNode();
-    if (type() == HTMLTagNodeListType)
+    if (type() == Type::HTMLTagNodeListType)
         return firstMatchingElement(static_cast<const HTMLTagNodeList*>(this), root);
-    if (type() == ClassNodeListType)
+    if (type() == Type::ClassNodeListType)
         return firstMatchingElement(static_cast<const ClassNodeList*>(this), root);
     return firstMatchingElement(static_cast<const LiveNodeList*>(this), root);
 }
@@ -116,9 +116,9 @@
 Element* LiveNodeList::collectionTraverseForward(Element& current, unsigned count, unsigned& traversedCount) const
 {
     auto& root = rootNode();
-    if (type() == HTMLTagNodeListType)
+    if (type() == Type::HTMLTagNodeListType)
         return traverseMatchingElementsForward(static_cast<const HTMLTagNodeList*>(this), current, count, traversedCount, root);
-    if (type() == ClassNodeListType)
+    if (type() == Type::ClassNodeListType)
         return traverseMatchingElementsForward(static_cast<const ClassNodeList*>(this), current, count, traversedCount, root);
     return traverseMatchingElementsForward(static_cast<const LiveNodeList*>(this), current, count, traversedCount, root);
 }

Modified: trunk/Source/WebCore/dom/LiveNodeList.h (164653 => 164654)


--- trunk/Source/WebCore/dom/LiveNodeList.h	2014-02-25 17:53:33 UTC (rev 164653)
+++ trunk/Source/WebCore/dom/LiveNodeList.h	2014-02-25 17:57:31 UTC (rev 164654)
@@ -45,7 +45,7 @@
 
 class LiveNodeList : public NodeList {
 public:
-    enum Type {
+    enum class Type {
         ClassNodeListType,
         NameNodeListType,
         TagNodeListType,
@@ -58,7 +58,7 @@
         : m_ownerNode(ownerNode)
         , m_rootType(rootType)
         , m_invalidationType(invalidationType)
-        , m_type(type)
+        , m_type(static_cast<unsigned>(type))
     {
         ASSERT(m_rootType == static_cast<unsigned>(rootType));
         ASSERT(m_invalidationType == static_cast<unsigned>(invalidationType));
@@ -111,9 +111,9 @@
 
     mutable CollectionIndexCache<LiveNodeList, Element> m_indexCache;
 
-    const unsigned m_rootType : 2;
+    const unsigned m_rootType : 1;
     const unsigned m_invalidationType : 4;
-    const unsigned m_type : 5;
+    const unsigned m_type : 3;
 };
 
 ALWAYS_INLINE bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType type, const QualifiedName& attrName)

Modified: trunk/Source/WebCore/dom/NameNodeList.cpp (164653 => 164654)


--- trunk/Source/WebCore/dom/NameNodeList.cpp	2014-02-25 17:53:33 UTC (rev 164653)
+++ trunk/Source/WebCore/dom/NameNodeList.cpp	2014-02-25 17:57:31 UTC (rev 164654)
@@ -30,7 +30,7 @@
 using namespace HTMLNames;
 
 NameNodeList::NameNodeList(ContainerNode& rootNode, const AtomicString& name)
-    : LiveNodeList(rootNode, NameNodeListType, InvalidateOnNameAttrChange)
+    : LiveNodeList(rootNode, Type::NameNodeListType, InvalidateOnNameAttrChange)
     , m_name(name)
 {
 }

Modified: trunk/Source/WebCore/dom/NameNodeList.h (164653 => 164654)


--- trunk/Source/WebCore/dom/NameNodeList.h	2014-02-25 17:53:33 UTC (rev 164653)
+++ trunk/Source/WebCore/dom/NameNodeList.h	2014-02-25 17:57:31 UTC (rev 164654)
@@ -35,7 +35,7 @@
 public:
     static PassRefPtr<NameNodeList> create(ContainerNode& rootNode, Type type, const AtomicString& name)
     {
-        ASSERT_UNUSED(type, type == NameNodeListType);
+        ASSERT_UNUSED(type, type == Type::NameNodeListType);
         return adoptRef(new NameNodeList(rootNode, name));
     }
 

Modified: trunk/Source/WebCore/dom/NodeRareData.h (164653 => 164654)


--- trunk/Source/WebCore/dom/NodeRareData.h	2014-02-25 17:53:33 UTC (rev 164653)
+++ trunk/Source/WebCore/dom/NodeRareData.h	2014-02-25 17:57:31 UTC (rev 164654)
@@ -262,7 +262,7 @@
 
     std::pair<unsigned char, String> namedNodeListKey(LiveNodeList::Type type, const String& name)
     {
-        return std::pair<unsigned char, String>(type, name);
+        return std::pair<unsigned char, String>(static_cast<unsigned char>(type), name);
     }
 
     bool deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node&);

Modified: trunk/Source/WebCore/dom/TagNodeList.cpp (164653 => 164654)


--- trunk/Source/WebCore/dom/TagNodeList.cpp	2014-02-25 17:53:33 UTC (rev 164653)
+++ trunk/Source/WebCore/dom/TagNodeList.cpp	2014-02-25 17:57:31 UTC (rev 164654)
@@ -54,7 +54,7 @@
 }
 
 HTMLTagNodeList::HTMLTagNodeList(ContainerNode& rootNode, const AtomicString& localName)
-    : TagNodeList(rootNode, HTMLTagNodeListType, starAtom, localName)
+    : TagNodeList(rootNode, Type::HTMLTagNodeListType, starAtom, localName)
     , m_loweredLocalName(localName.lower())
 {
 }

Modified: trunk/Source/WebCore/dom/TagNodeList.h (164653 => 164654)


--- trunk/Source/WebCore/dom/TagNodeList.h	2014-02-25 17:53:33 UTC (rev 164653)
+++ trunk/Source/WebCore/dom/TagNodeList.h	2014-02-25 17:57:31 UTC (rev 164654)
@@ -36,13 +36,13 @@
     static PassRefPtr<TagNodeList> create(ContainerNode& rootNode, const AtomicString& namespaceURI, const AtomicString& localName)
     {
         ASSERT(namespaceURI != starAtom);
-        return adoptRef(new TagNodeList(rootNode, TagNodeListType, namespaceURI, localName));
+        return adoptRef(new TagNodeList(rootNode, Type::TagNodeListType, namespaceURI, localName));
     }
 
     static PassRefPtr<TagNodeList> create(ContainerNode& rootNode, Type type, const AtomicString& localName)
     {
-        ASSERT_UNUSED(type, type == TagNodeListType);
-        return adoptRef(new TagNodeList(rootNode, TagNodeListType, starAtom, localName));
+        ASSERT_UNUSED(type, type == Type::TagNodeListType);
+        return adoptRef(new TagNodeList(rootNode, Type::TagNodeListType, starAtom, localName));
     }
 
     virtual ~TagNodeList();
@@ -60,7 +60,7 @@
 public:
     static PassRefPtr<HTMLTagNodeList> create(ContainerNode& rootNode, Type type, const AtomicString& localName)
     {
-        ASSERT_UNUSED(type, type == HTMLTagNodeListType);
+        ASSERT_UNUSED(type, type == Type::HTMLTagNodeListType);
         return adoptRef(new HTMLTagNodeList(rootNode, localName));
     }
 

Modified: trunk/Source/WebCore/html/HTMLCollection.h (164653 => 164654)


--- trunk/Source/WebCore/html/HTMLCollection.h	2014-02-25 17:53:33 UTC (rev 164653)
+++ trunk/Source/WebCore/html/HTMLCollection.h	2014-02-25 17:57:31 UTC (rev 164654)
@@ -111,7 +111,7 @@
 
     mutable CollectionIndexCache<HTMLCollection, Element> m_indexCache;
 
-    const unsigned m_rootType : 2;
+    const unsigned m_rootType : 1;
     const unsigned m_invalidationType : 4;
     const unsigned m_shouldOnlyIncludeDirectChildren : 1;
 

Modified: trunk/Source/WebCore/html/LabelableElement.cpp (164653 => 164654)


--- trunk/Source/WebCore/html/LabelableElement.cpp	2014-02-25 17:53:33 UTC (rev 164653)
+++ trunk/Source/WebCore/html/LabelableElement.cpp	2014-02-25 17:57:31 UTC (rev 164654)
@@ -45,7 +45,7 @@
     if (!supportLabels())
         return 0;
 
-    return ensureRareData().ensureNodeLists().addCacheWithAtomicName<LabelsNodeList>(*this, LiveNodeList::LabelsNodeListType, starAtom);
+    return ensureRareData().ensureNodeLists().addCacheWithAtomicName<LabelsNodeList>(*this, LiveNodeList::Type::LabelsNodeListType, starAtom);
 }
 
 } // namespace Webcore

Modified: trunk/Source/WebCore/html/LabelsNodeList.cpp (164653 => 164654)


--- trunk/Source/WebCore/html/LabelsNodeList.cpp	2014-02-25 17:53:33 UTC (rev 164653)
+++ trunk/Source/WebCore/html/LabelsNodeList.cpp	2014-02-25 17:57:31 UTC (rev 164654)
@@ -34,7 +34,7 @@
 using namespace HTMLNames;
 
 LabelsNodeList::LabelsNodeList(LabelableElement& forNode)
-    : LiveNodeList(forNode, LabelsNodeListType, InvalidateOnForAttrChange, NodeListIsRootedAtDocument)
+    : LiveNodeList(forNode, Type::LabelsNodeListType, InvalidateOnForAttrChange, NodeListIsRootedAtDocument)
 {
 }
 

Modified: trunk/Source/WebCore/html/LabelsNodeList.h (164653 => 164654)


--- trunk/Source/WebCore/html/LabelsNodeList.h	2014-02-25 17:53:33 UTC (rev 164653)
+++ trunk/Source/WebCore/html/LabelsNodeList.h	2014-02-25 17:57:31 UTC (rev 164654)
@@ -34,7 +34,7 @@
 public:
     static PassRef<LabelsNodeList> create(LabelableElement& forNode, Type type, const AtomicString&)
     {
-        ASSERT_UNUSED(type, type == LabelsNodeListType);
+        ASSERT_UNUSED(type, type == Type::LabelsNodeListType);
         return adoptRef(*new LabelsNodeList(forNode));
     }
     ~LabelsNodeList();

Modified: trunk/Source/WebCore/html/RadioNodeList.cpp (164653 => 164654)


--- trunk/Source/WebCore/html/RadioNodeList.cpp	2014-02-25 17:53:33 UTC (rev 164653)
+++ trunk/Source/WebCore/html/RadioNodeList.cpp	2014-02-25 17:57:31 UTC (rev 164654)
@@ -38,7 +38,7 @@
 using namespace HTMLNames;
 
 RadioNodeList::RadioNodeList(ContainerNode& rootNode, const AtomicString& name)
-    : LiveNodeList(rootNode, RadioNodeListType, InvalidateForFormControls, isHTMLFormElement(rootNode) ? NodeListIsRootedAtDocument : NodeListIsRootedAtNode)
+    : LiveNodeList(rootNode, Type::RadioNodeListType, InvalidateForFormControls, isHTMLFormElement(rootNode) ? NodeListIsRootedAtDocument : NodeListIsRootedAtNode)
     , m_name(name)
 {
 }

Modified: trunk/Source/WebCore/html/RadioNodeList.h (164653 => 164654)


--- trunk/Source/WebCore/html/RadioNodeList.h	2014-02-25 17:53:33 UTC (rev 164653)
+++ trunk/Source/WebCore/html/RadioNodeList.h	2014-02-25 17:57:31 UTC (rev 164654)
@@ -36,7 +36,7 @@
 public:
     static PassRefPtr<RadioNodeList> create(ContainerNode& rootNode, Type type, const AtomicString& name)
     {
-        ASSERT_UNUSED(type, type == RadioNodeListType);
+        ASSERT_UNUSED(type, type == Type::RadioNodeListType);
         return adoptRef(new RadioNodeList(rootNode, name));
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to