Tighten bitfields in live NodeLists and HTMLCollections
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Feb 2014 17:57:31 +0000 (17:57 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Feb 2014 17:57:31 +0000 (17:57 +0000)
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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@164654 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/ClassNodeList.cpp
Source/WebCore/dom/ContainerNode.cpp
Source/WebCore/dom/LiveNodeList.cpp
Source/WebCore/dom/LiveNodeList.h
Source/WebCore/dom/NameNodeList.cpp
Source/WebCore/dom/NameNodeList.h
Source/WebCore/dom/NodeRareData.h
Source/WebCore/dom/TagNodeList.cpp
Source/WebCore/dom/TagNodeList.h
Source/WebCore/html/HTMLCollection.h
Source/WebCore/html/LabelableElement.cpp
Source/WebCore/html/LabelsNodeList.cpp
Source/WebCore/html/LabelsNodeList.h
Source/WebCore/html/RadioNodeList.cpp
Source/WebCore/html/RadioNodeList.h

index 70c11a52cf61b178180eb527b8d150ab67252a23..ff650c5752a10e245e4241fc1ec0185f0f583820 100644 (file)
@@ -1,3 +1,48 @@
+2014-02-25  Ryosuke Niwa  <rniwa@webkit.org>
+
+        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  <andersca@apple.com>
 
         Make it possible to set the visited link provider on a per page basis
index 2cd99b1ebdcdbc4a1177182c3d31f7ad7984e4cb..7be2dd0485a29e477f1d6c4ce357dc756ec08b98 100644 (file)
@@ -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)
 {
index 63f752fcbbec788f6ac906ea1322927fc6f0be6d..8607f70151d723d257000dacb2a604d37a527cb3 100644 (file)
@@ -1103,8 +1103,8 @@ PassRefPtr<NodeList> ContainerNode::getElementsByTagName(const AtomicString& loc
         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::getElementsByTagNameNS(const AtomicString& n
 
 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
index 0a15793b95a8c664b9438067ed156b16fd14ec73..5a0dc22ad4d8c8b27928f12e5fb8a38ed2e257f3 100644 (file)
@@ -100,9 +100,9 @@ inline Element* traverseMatchingElementsForward(const NodeListType* nodeList, El
 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::collectionLast() const
 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);
 }
index 6e8ee08e57d2ae7b9291826d78ebd293daa67ca4..7cbc1b964ff6dbfc6f71d3f57c674341d272f846 100644 (file)
@@ -45,7 +45,7 @@ static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType, cons
 
 class LiveNodeList : public NodeList {
 public:
-    enum Type {
+    enum class Type {
         ClassNodeListType,
         NameNodeListType,
         TagNodeListType,
@@ -58,7 +58,7 @@ public:
         : 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 @@ private:
 
     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)
index e26abac462eebd616284b3c9a46df3e6b2931415..6fd4545be85e666f1f8129da01aa0106403b947f 100644 (file)
@@ -30,7 +30,7 @@ namespace WebCore {
 using namespace HTMLNames;
 
 NameNodeList::NameNodeList(ContainerNode& rootNode, const AtomicString& name)
-    : LiveNodeList(rootNode, NameNodeListType, InvalidateOnNameAttrChange)
+    : LiveNodeList(rootNode, Type::NameNodeListType, InvalidateOnNameAttrChange)
     , m_name(name)
 {
 }
index c7b4310626c96b23d9356b88c085ae97915b0f48..2a369513f13aec097bb81377b0457c251bb60fa9 100644 (file)
@@ -35,7 +35,7 @@ class NameNodeList : public LiveNodeList {
 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));
     }
 
index cd1742fbf9adb362e74bc4f8ab12fc63faee9f42..6459cf532da63a227b5384bab87dcecf20adc53f 100644 (file)
@@ -262,7 +262,7 @@ private:
 
     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&);
index 9f4a4f4ba70dc9a10e6da2ea8ea6de6e89eeb0d7..a011e6c59255e63b236bec9f600829a431edd5d7 100644 (file)
@@ -54,7 +54,7 @@ bool TagNodeList::nodeMatches(Element* testNode) const
 }
 
 HTMLTagNodeList::HTMLTagNodeList(ContainerNode& rootNode, const AtomicString& localName)
-    : TagNodeList(rootNode, HTMLTagNodeListType, starAtom, localName)
+    : TagNodeList(rootNode, Type::HTMLTagNodeListType, starAtom, localName)
     , m_loweredLocalName(localName.lower())
 {
 }
index bd098bf804bbf385f20b0943502fb23b6341c20d..0009fdb4c9ff528e1eddd8b9216a258d0b59e667 100644 (file)
@@ -36,13 +36,13 @@ public:
     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 @@ class HTMLTagNodeList : public TagNodeList {
 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));
     }
 
index 17c81c7e1c0aeaf631696bf80ebb0090123a98bb..e3e44beb6cc5feea8f4027056e3314641dcb72b4 100644 (file)
@@ -111,7 +111,7 @@ private:
 
     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;
 
index 1d4d7f937315bbf5858c521e8e64043bed80f46d..f4b1fd998582c4f561dfaf0be76f672d7ea4aa3c 100644 (file)
@@ -45,7 +45,7 @@ PassRefPtr<NodeList> LabelableElement::labels()
     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
index 8a9a348cec55e49c1c4095db40988d783f23da93..a09b4d752e0a15d9e16db30803a28afc0443f790 100644 (file)
@@ -34,7 +34,7 @@ namespace WebCore {
 using namespace HTMLNames;
 
 LabelsNodeList::LabelsNodeList(LabelableElement& forNode)
-    : LiveNodeList(forNode, LabelsNodeListType, InvalidateOnForAttrChange, NodeListIsRootedAtDocument)
+    : LiveNodeList(forNode, Type::LabelsNodeListType, InvalidateOnForAttrChange, NodeListIsRootedAtDocument)
 {
 }
 
index 5a1d4004096a9d93928a10d6aaa9e03294f0f3c0..88271fa8268cf38db5a312950fe08043b53469e7 100644 (file)
@@ -34,7 +34,7 @@ class LabelsNodeList final : public LiveNodeList {
 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();
index ad7dc76010e69f50dec24d4507708ca3ca592b1a..ccd4093f21b446d2e883dee484b58562a989ba52 100644 (file)
@@ -38,7 +38,7 @@ namespace WebCore {
 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)
 {
 }
index f82264ed4ef4c9eb969dc307426f1e27d740a277..281aa7fadb438ef573360a241e6175d37bf148e0 100644 (file)
@@ -36,7 +36,7 @@ class RadioNodeList : public LiveNodeList {
 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));
     }