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
+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
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)
{
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)
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
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);
}
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);
}
class LiveNodeList : public NodeList {
public:
- enum Type {
+ enum class Type {
ClassNodeListType,
NameNodeListType,
TagNodeListType,
: 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));
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)
using namespace HTMLNames;
NameNodeList::NameNodeList(ContainerNode& rootNode, const AtomicString& name)
- : LiveNodeList(rootNode, NameNodeListType, InvalidateOnNameAttrChange)
+ : LiveNodeList(rootNode, Type::NameNodeListType, InvalidateOnNameAttrChange)
, m_name(name)
{
}
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));
}
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&);
}
HTMLTagNodeList::HTMLTagNodeList(ContainerNode& rootNode, const AtomicString& localName)
- : TagNodeList(rootNode, HTMLTagNodeListType, starAtom, localName)
+ : TagNodeList(rootNode, Type::HTMLTagNodeListType, starAtom, localName)
, m_loweredLocalName(localName.lower())
{
}
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();
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));
}
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;
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
using namespace HTMLNames;
LabelsNodeList::LabelsNodeList(LabelableElement& forNode)
- : LiveNodeList(forNode, LabelsNodeListType, InvalidateOnForAttrChange, NodeListIsRootedAtDocument)
+ : LiveNodeList(forNode, Type::LabelsNodeListType, InvalidateOnForAttrChange, NodeListIsRootedAtDocument)
{
}
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();
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)
{
}
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));
}