Changeset 166377 in webkit


Ignore:
Timestamp:
Mar 27, 2014, 3:47:15 PM (11 years ago)
Author:
Antti Koivisto
Message:

Remove LiveNodeList::Type
https://bugs.webkit.org/show_bug.cgi?id=130866

Reviewed by Andreas Kling.

We don't need dynamic type information anymore.

  • 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::LiveNodeList):

  • dom/LiveNodeList.h:

(WebCore::LiveNodeList::invalidationType):
(WebCore::CachedLiveNodeList<NodeListType>::CachedLiveNodeList):
(WebCore::LiveNodeList::type): Deleted.

  • dom/NameNodeList.cpp:

(WebCore::NameNodeList::NameNodeList):
(WebCore::NameNodeList::nodeMatches): Deleted.

  • dom/NameNodeList.h:

(WebCore::NameNodeList::nodeMatches):

  • dom/NodeRareData.h:

(WebCore::NodeListTypeIdentifier<ClassNodeList>::value):
(WebCore::NodeListTypeIdentifier<NameNodeList>::value):
(WebCore::NodeListTypeIdentifier<TagNodeList>::value):
(WebCore::NodeListTypeIdentifier<HTMLTagNodeList>::value):
(WebCore::NodeListTypeIdentifier<RadioNodeList>::value):
(WebCore::NodeListTypeIdentifier<LabelsNodeList>::value):

Get unique id from type for key generation purposes only.

(WebCore::NodeListsNodeData::addCacheWithAtomicName):
(WebCore::NodeListsNodeData::addCacheWithName):
(WebCore::NodeListsNodeData::removeCacheWithAtomicName):
(WebCore::NodeListsNodeData::removeCacheWithName):
(WebCore::NodeListsNodeData::namedNodeListKey):

  • dom/TagNodeList.cpp:

(WebCore::TagNodeList::TagNodeList):
(WebCore::HTMLTagNodeList::HTMLTagNodeList):

  • dom/TagNodeList.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:
Location:
trunk/Source/WebCore
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r166372 r166377  
     12014-03-27  Antti Koivisto  <antti@apple.com>
     2
     3        Remove LiveNodeList::Type
     4        https://bugs.webkit.org/show_bug.cgi?id=130866
     5
     6        Reviewed by Andreas Kling.
     7
     8        We don't need dynamic type information anymore.
     9
     10        * dom/ClassNodeList.cpp:
     11        (WebCore::ClassNodeList::ClassNodeList):
     12        * dom/ContainerNode.cpp:
     13        (WebCore::ContainerNode::getElementsByTagName):
     14        (WebCore::ContainerNode::getElementsByName):
     15        (WebCore::ContainerNode::getElementsByClassName):
     16        (WebCore::ContainerNode::radioNodeList):
     17        * dom/LiveNodeList.cpp:
     18        (WebCore::LiveNodeList::LiveNodeList):
     19        * dom/LiveNodeList.h:
     20        (WebCore::LiveNodeList::invalidationType):
     21        (WebCore::CachedLiveNodeList<NodeListType>::CachedLiveNodeList):
     22        (WebCore::LiveNodeList::type): Deleted.
     23        * dom/NameNodeList.cpp:
     24        (WebCore::NameNodeList::NameNodeList):
     25        (WebCore::NameNodeList::nodeMatches): Deleted.
     26        * dom/NameNodeList.h:
     27        (WebCore::NameNodeList::nodeMatches):
     28        * dom/NodeRareData.h:
     29        (WebCore::NodeListTypeIdentifier<ClassNodeList>::value):
     30        (WebCore::NodeListTypeIdentifier<NameNodeList>::value):
     31        (WebCore::NodeListTypeIdentifier<TagNodeList>::value):
     32        (WebCore::NodeListTypeIdentifier<HTMLTagNodeList>::value):
     33        (WebCore::NodeListTypeIdentifier<RadioNodeList>::value):
     34        (WebCore::NodeListTypeIdentifier<LabelsNodeList>::value):
     35       
     36            Get unique id from type for key generation purposes only.
     37
     38        (WebCore::NodeListsNodeData::addCacheWithAtomicName):
     39        (WebCore::NodeListsNodeData::addCacheWithName):
     40        (WebCore::NodeListsNodeData::removeCacheWithAtomicName):
     41        (WebCore::NodeListsNodeData::removeCacheWithName):
     42        (WebCore::NodeListsNodeData::namedNodeListKey):
     43        * dom/TagNodeList.cpp:
     44        (WebCore::TagNodeList::TagNodeList):
     45        (WebCore::HTMLTagNodeList::HTMLTagNodeList):
     46        * dom/TagNodeList.h:
     47        * html/LabelableElement.cpp:
     48        (WebCore::LabelableElement::labels):
     49        * html/LabelsNodeList.cpp:
     50        (WebCore::LabelsNodeList::LabelsNodeList):
     51        * html/LabelsNodeList.h:
     52        * html/RadioNodeList.cpp:
     53        (WebCore::RadioNodeList::RadioNodeList):
     54        * html/RadioNodeList.h:
     55
    1562014-03-27  Simon Fraser  <simon.fraser@apple.com>
    257
  • trunk/Source/WebCore/dom/ClassNodeList.cpp

    r166369 r166377  
    3737
    3838ClassNodeList::ClassNodeList(ContainerNode& rootNode, const String& classNames)
    39     : CachedLiveNodeList(rootNode, Type::ClassNodeListType, InvalidateOnClassAttrChange)
     39    : CachedLiveNodeList(rootNode, InvalidateOnClassAttrChange)
    4040    , m_classNames(classNames, document().inQuirksMode())
    4141    , m_originalClassNames(classNames)
  • trunk/Source/WebCore/dom/ContainerNode.cpp

    r166354 r166377  
    10191019
    10201020    if (document().isHTMLDocument())
    1021         return ensureRareData().ensureNodeLists().addCacheWithAtomicName<HTMLTagNodeList>(*this, LiveNodeList::Type::HTMLTagNodeListType, localName);
    1022     return ensureRareData().ensureNodeLists().addCacheWithAtomicName<TagNodeList>(*this, LiveNodeList::Type::TagNodeListType, localName);
     1021        return ensureRareData().ensureNodeLists().addCacheWithAtomicName<HTMLTagNodeList>(*this, localName);
     1022    return ensureRareData().ensureNodeLists().addCacheWithAtomicName<TagNodeList>(*this, localName);
    10231023}
    10241024
     
    10361036PassRefPtr<NodeList> ContainerNode::getElementsByName(const String& elementName)
    10371037{
    1038     return ensureRareData().ensureNodeLists().addCacheWithAtomicName<NameNodeList>(*this, LiveNodeList::Type::NameNodeListType, elementName);
     1038    return ensureRareData().ensureNodeLists().addCacheWithAtomicName<NameNodeList>(*this, elementName);
    10391039}
    10401040
    10411041PassRefPtr<NodeList> ContainerNode::getElementsByClassName(const String& classNames)
    10421042{
    1043     return ensureRareData().ensureNodeLists().addCacheWithName<ClassNodeList>(*this, LiveNodeList::Type::ClassNodeListType, classNames);
     1043    return ensureRareData().ensureNodeLists().addCacheWithName<ClassNodeList>(*this, classNames);
    10441044}
    10451045
     
    10471047{
    10481048    ASSERT(hasTagName(HTMLNames::formTag) || hasTagName(HTMLNames::fieldsetTag));
    1049     return ensureRareData().ensureNodeLists().addCacheWithAtomicName<RadioNodeList>(*this, LiveNodeList::Type::RadioNodeListType, name);
     1049    return ensureRareData().ensureNodeLists().addCacheWithAtomicName<RadioNodeList>(*this, name);
    10501050}
    10511051
  • trunk/Source/WebCore/dom/LiveNodeList.cpp

    r166369 r166377  
    3232namespace WebCore {
    3333
    34 LiveNodeList::LiveNodeList(ContainerNode& ownerNode, Type type, NodeListInvalidationType invalidationType, NodeListRootType rootType)
     34LiveNodeList::LiveNodeList(ContainerNode& ownerNode, NodeListInvalidationType invalidationType, NodeListRootType rootType)
    3535    : m_ownerNode(ownerNode)
    3636    , m_rootType(rootType)
    3737    , m_invalidationType(invalidationType)
    38     , m_type(static_cast<unsigned>(type))
    3938{
    4039    ASSERT(m_rootType == static_cast<unsigned>(rootType));
    4140    ASSERT(m_invalidationType == static_cast<unsigned>(invalidationType));
    42     ASSERT(m_type == static_cast<unsigned>(type));
    4341}
    4442
  • trunk/Source/WebCore/dom/LiveNodeList.h

    r166369 r166377  
    4747class LiveNodeList : public NodeList {
    4848public:
    49     enum class Type {
    50         ClassNodeListType,
    51         NameNodeListType,
    52         TagNodeListType,
    53         HTMLTagNodeListType,
    54         RadioNodeListType,
    55         LabelsNodeListType,
    56     };
    57 
    58     LiveNodeList(ContainerNode& ownerNode, Type, NodeListInvalidationType, NodeListRootType);
     49    LiveNodeList(ContainerNode& ownerNode, NodeListInvalidationType, NodeListRootType);
    5950    virtual Node* namedItem(const AtomicString&) const override final;
    6051    virtual bool nodeMatches(Element*) const = 0;
     
    6455    ALWAYS_INLINE bool isRootedAtDocument() const { return m_rootType == NodeListIsRootedAtDocument; }
    6556    ALWAYS_INLINE NodeListInvalidationType invalidationType() const { return static_cast<NodeListInvalidationType>(m_invalidationType); }
    66     ALWAYS_INLINE Type type() const { return static_cast<Type>(m_type); }
    6757    ContainerNode& ownerNode() const { return const_cast<ContainerNode&>(m_ownerNode.get()); }
    6858    ALWAYS_INLINE void invalidateCacheForAttribute(const QualifiedName* attrName) const
     
    8878    const unsigned m_rootType : 1;
    8979    const unsigned m_invalidationType : 4;
    90     const unsigned m_type : 3;
    9180};
    9281
     
    111100
    112101protected:
    113     CachedLiveNodeList(ContainerNode& rootNode, Type, NodeListInvalidationType, NodeListRootType = NodeListIsRootedAtNode);
     102    CachedLiveNodeList(ContainerNode& rootNode, NodeListInvalidationType, NodeListRootType = NodeListIsRootedAtNode);
    114103
    115104private:
     
    150139
    151140template <class NodeListType>
    152 CachedLiveNodeList<NodeListType>::CachedLiveNodeList(ContainerNode& ownerNode, Type type, NodeListInvalidationType invalidationType, NodeListRootType rootType)
    153     : LiveNodeList(ownerNode, type, invalidationType, rootType)
     141CachedLiveNodeList<NodeListType>::CachedLiveNodeList(ContainerNode& ownerNode, NodeListInvalidationType invalidationType, NodeListRootType rootType)
     142    : LiveNodeList(ownerNode, invalidationType, rootType)
    154143{
    155144}
  • trunk/Source/WebCore/dom/NameNodeList.cpp

    r166369 r166377  
    3131
    3232NameNodeList::NameNodeList(ContainerNode& rootNode, const AtomicString& name)
    33     : CachedLiveNodeList(rootNode, Type::NameNodeListType, InvalidateOnNameAttrChange)
     33    : CachedLiveNodeList(rootNode, InvalidateOnNameAttrChange)
    3434    , m_name(name)
    3535{
     
    4141}
    4242
    43 bool NameNodeList::nodeMatches(Element* testNode) const
    44 {
    45     return testNode->getNameAttribute() == m_name;
    46 }
    47 
    4843} // namespace WebCore
  • trunk/Source/WebCore/dom/NameNodeList.h

    r166369 r166377  
    3434class NameNodeList final : public CachedLiveNodeList<NameNodeList> {
    3535public:
    36     static PassRefPtr<NameNodeList> create(ContainerNode& rootNode, Type type, const AtomicString& name)
     36    static PassRefPtr<NameNodeList> create(ContainerNode& rootNode, const AtomicString& name)
    3737    {
    38         ASSERT_UNUSED(type, type == Type::NameNodeListType);
    3938        return adoptRef(new NameNodeList(rootNode, name));
    4039    }
     
    5049};
    5150
     51inline bool NameNodeList::nodeMatches(Element* element) const
     52{
     53    return element->getNameAttribute() == m_name;
     54}
     55
    5256} // namespace WebCore
    5357
  • trunk/Source/WebCore/dom/NodeRareData.h

    r165546 r166377  
    5050class TreeScope;
    5151
     52template <class ListType> struct NodeListTypeIdentifier;
     53template <> struct NodeListTypeIdentifier<ClassNodeList> { static int value() { return 0; } };
     54template <> struct NodeListTypeIdentifier<NameNodeList> { static int value() { return 1; } };
     55template <> struct NodeListTypeIdentifier<TagNodeList> { static int value() { return 2; } };
     56template <> struct NodeListTypeIdentifier<HTMLTagNodeList> { static int value() { return 3; } };
     57template <> struct NodeListTypeIdentifier<RadioNodeList> { static int value() { return 4; } };
     58template <> struct NodeListTypeIdentifier<LabelsNodeList> { static int value() { return 5; } };
     59
    5260class NodeListsNodeData {
    5361    WTF_MAKE_NONCOPYABLE(NodeListsNodeData); WTF_MAKE_FAST_ALLOCATED;
     
    111119
    112120    template<typename T, typename ContainerType>
    113     PassRefPtr<T> addCacheWithAtomicName(ContainerType& container, LiveNodeList::Type type, const AtomicString& name)
    114     {
    115         NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(namedNodeListKey(type, name), nullptr);
     121    PassRefPtr<T> addCacheWithAtomicName(ContainerType& container, const AtomicString& name)
     122    {
     123        NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(namedNodeListKey<T>(name), nullptr);
    116124        if (!result.isNewEntry)
    117125            return static_cast<T*>(result.iterator->value);
    118126
    119         RefPtr<T> list = T::create(container, type, name);
     127        RefPtr<T> list = T::create(container, name);
    120128        result.iterator->value = list.get();
    121129        return list.release();
     
    123131
    124132    template<typename T>
    125     PassRefPtr<T> addCacheWithName(ContainerNode& node, LiveNodeList::Type type, const String& name)
    126     {
    127         NodeListNameCacheMap::AddResult result = m_nameCaches.add(namedNodeListKey(type, name), nullptr);
     133    PassRefPtr<T> addCacheWithName(ContainerNode& node, const String& name)
     134    {
     135        NodeListNameCacheMap::AddResult result = m_nameCaches.add(namedNodeListKey<T>(name), nullptr);
    128136        if (!result.isNewEntry)
    129137            return static_cast<T*>(result.iterator->value);
     
    176184    }
    177185
    178     void removeCacheWithAtomicName(LiveNodeList* list, const AtomicString& name = starAtom)
    179     {
    180         ASSERT(list == m_atomicNameCaches.get(namedNodeListKey(list->type(), name)));
    181         if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNode()))
    182             return;
    183         m_atomicNameCaches.remove(namedNodeListKey(list->type(), name));
    184     }
    185 
    186     void removeCacheWithName(LiveNodeList* list, const String& name)
    187     {
    188         ASSERT(list == m_nameCaches.get(namedNodeListKey(list->type(), name)));
    189         if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNode()))
    190             return;
    191         m_nameCaches.remove(namedNodeListKey(list->type(), name));
     186    template <class NodeListType>
     187    void removeCacheWithAtomicName(NodeListType* list, const AtomicString& name = starAtom)
     188    {
     189        ASSERT(list == m_atomicNameCaches.get(namedNodeListKey<NodeListType>(name)));
     190        if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNode()))
     191            return;
     192        m_atomicNameCaches.remove(namedNodeListKey<NodeListType>(name));
     193    }
     194
     195    template <class NodeListType>
     196    void removeCacheWithName(NodeListType* list, const String& name)
     197    {
     198        ASSERT(list == m_nameCaches.get(namedNodeListKey<NodeListType>(name)));
     199        if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNode()))
     200            return;
     201        m_nameCaches.remove(namedNodeListKey<NodeListType>(name));
    192202    }
    193203
     
    260270    }
    261271
    262     std::pair<unsigned char, String> namedNodeListKey(LiveNodeList::Type type, const String& name)
    263     {
    264         return std::pair<unsigned char, String>(static_cast<unsigned char>(type), name);
     272    template <class NodeListType>
     273    std::pair<unsigned char, String> namedNodeListKey(const String& name)
     274    {
     275        return std::pair<unsigned char, String>(NodeListTypeIdentifier<NodeListType>::value(), name);
    265276    }
    266277
  • trunk/Source/WebCore/dom/TagNodeList.cpp

    r166369 r166377  
    3030
    3131TagNodeList::TagNodeList(ContainerNode& rootNode, const AtomicString& namespaceURI, const AtomicString& localName)
    32     : CachedLiveNodeList(rootNode, Type::TagNodeListType, DoNotInvalidateOnAttributeChanges)
     32    : CachedLiveNodeList(rootNode, DoNotInvalidateOnAttributeChanges)
    3333    , m_namespaceURI(namespaceURI)
    3434    , m_localName(localName)
     
    4646
    4747HTMLTagNodeList::HTMLTagNodeList(ContainerNode& rootNode, const AtomicString& localName)
    48     : CachedLiveNodeList(rootNode, Type::HTMLTagNodeListType, DoNotInvalidateOnAttributeChanges)
     48    : CachedLiveNodeList(rootNode, DoNotInvalidateOnAttributeChanges)
    4949    , m_localName(localName)
    5050    , m_loweredLocalName(localName.lower())
  • trunk/Source/WebCore/dom/TagNodeList.h

    r166369 r166377  
    4040    }
    4141
    42     static PassRefPtr<TagNodeList> create(ContainerNode& rootNode, Type type, const AtomicString& localName)
     42    static PassRefPtr<TagNodeList> create(ContainerNode& rootNode, const AtomicString& localName)
    4343    {
    44         ASSERT_UNUSED(type, type == Type::TagNodeListType);
    4544        return adoptRef(new TagNodeList(rootNode, starAtom, localName));
    4645    }
     
    6867class HTMLTagNodeList final : public CachedLiveNodeList<HTMLTagNodeList> {
    6968public:
    70     static PassRefPtr<HTMLTagNodeList> create(ContainerNode& rootNode, Type type, const AtomicString& localName)
     69    static PassRefPtr<HTMLTagNodeList> create(ContainerNode& rootNode, const AtomicString& localName)
    7170    {
    72         ASSERT_UNUSED(type, type == Type::HTMLTagNodeListType);
    7371        return adoptRef(new HTMLTagNodeList(rootNode, localName));
    7472    }
  • trunk/Source/WebCore/html/LabelableElement.cpp

    r164654 r166377  
    4646        return 0;
    4747
    48     return ensureRareData().ensureNodeLists().addCacheWithAtomicName<LabelsNodeList>(*this, LiveNodeList::Type::LabelsNodeListType, starAtom);
     48    return ensureRareData().ensureNodeLists().addCacheWithAtomicName<LabelsNodeList>(*this, starAtom);
    4949}
    5050
  • trunk/Source/WebCore/html/LabelsNodeList.cpp

    r166369 r166377  
    3535
    3636LabelsNodeList::LabelsNodeList(LabelableElement& forNode)
    37     : CachedLiveNodeList(forNode, Type::LabelsNodeListType, InvalidateOnForAttrChange, NodeListIsRootedAtDocument)
     37    : CachedLiveNodeList(forNode, InvalidateOnForAttrChange, NodeListIsRootedAtDocument)
    3838{
    3939}
  • trunk/Source/WebCore/html/LabelsNodeList.h

    r166369 r166377  
    3333class LabelsNodeList final : public CachedLiveNodeList<LabelsNodeList> {
    3434public:
    35     static PassRef<LabelsNodeList> create(LabelableElement& forNode, Type type, const AtomicString&)
     35    static PassRef<LabelsNodeList> create(LabelableElement& forNode, const AtomicString&)
    3636    {
    37         ASSERT_UNUSED(type, type == Type::LabelsNodeListType);
    3837        return adoptRef(*new LabelsNodeList(forNode));
    3938    }
  • trunk/Source/WebCore/html/RadioNodeList.cpp

    r166369 r166377  
    3939
    4040RadioNodeList::RadioNodeList(ContainerNode& rootNode, const AtomicString& name)
    41     : CachedLiveNodeList(rootNode, Type::RadioNodeListType, InvalidateForFormControls, isHTMLFormElement(rootNode) ? NodeListIsRootedAtDocument : NodeListIsRootedAtNode)
     41    : CachedLiveNodeList(rootNode, InvalidateForFormControls, isHTMLFormElement(rootNode) ? NodeListIsRootedAtDocument : NodeListIsRootedAtNode)
    4242    , m_name(name)
    4343{
  • trunk/Source/WebCore/html/RadioNodeList.h

    r166369 r166377  
    3535class RadioNodeList final : public CachedLiveNodeList<RadioNodeList> {
    3636public:
    37     static PassRefPtr<RadioNodeList> create(ContainerNode& rootNode, Type type, const AtomicString& name)
     37    static PassRefPtr<RadioNodeList> create(ContainerNode& rootNode, const AtomicString& name)
    3838    {
    39         ASSERT_UNUSED(type, type == Type::RadioNodeListType);
    4039        return adoptRef(new RadioNodeList(rootNode, name));
    4140    }
Note: See TracChangeset for help on using the changeset viewer.