Changeset 166461 in webkit


Ignore:
Timestamp:
Mar 30, 2014 3:48:32 AM (10 years ago)
Author:
akling@apple.com
Message:

Make NodeList and HTMLCollection caching helpers use PassRef.
<https://webkit.org/b/130943>

Tweak the helpers in NodeListsNodeData to return PassRef instead of
PassRefPtr. This knocks 2 branches off of some pretty hot code on
Dromaeo/dom-query.

Reviewed by Antti Koivisto.

  • dom/ChildNodeList.h:
  • dom/ClassNodeList.h:
  • dom/NameNodeList.h:
  • dom/NodeRareData.h:

(WebCore::NodeListsNodeData::ensureChildNodeList):
(WebCore::NodeListsNodeData::ensureEmptyChildNodeList):
(WebCore::NodeListsNodeData::addCacheWithAtomicName):
(WebCore::NodeListsNodeData::addCacheWithName):
(WebCore::NodeListsNodeData::addCacheWithQualifiedName):
(WebCore::NodeListsNodeData::addCachedCollection):

  • dom/TagNodeList.h:
  • html/HTMLCollection.cpp:

(WebCore::HTMLCollection::create):

  • html/HTMLCollection.h:
  • html/HTMLFormControlsCollection.cpp:

(WebCore::HTMLFormControlsCollection::create):

  • html/HTMLFormControlsCollection.h:
  • html/RadioNodeList.h:
Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r166460 r166461  
     12014-03-30  Andreas Kling  <akling@apple.com>
     2
     3        Make NodeList and HTMLCollection caching helpers use PassRef.
     4        <https://webkit.org/b/130943>
     5
     6        Tweak the helpers in NodeListsNodeData to return PassRef instead of
     7        PassRefPtr. This knocks 2 branches off of some pretty hot code on
     8        Dromaeo/dom-query.
     9
     10        Reviewed by Antti Koivisto.
     11
     12        * dom/ChildNodeList.h:
     13        * dom/ClassNodeList.h:
     14        * dom/NameNodeList.h:
     15        * dom/NodeRareData.h:
     16        (WebCore::NodeListsNodeData::ensureChildNodeList):
     17        (WebCore::NodeListsNodeData::ensureEmptyChildNodeList):
     18        (WebCore::NodeListsNodeData::addCacheWithAtomicName):
     19        (WebCore::NodeListsNodeData::addCacheWithName):
     20        (WebCore::NodeListsNodeData::addCacheWithQualifiedName):
     21        (WebCore::NodeListsNodeData::addCachedCollection):
     22        * dom/TagNodeList.h:
     23        * html/HTMLCollection.cpp:
     24        (WebCore::HTMLCollection::create):
     25        * html/HTMLCollection.h:
     26        * html/HTMLFormControlsCollection.cpp:
     27        (WebCore::HTMLFormControlsCollection::create):
     28        * html/HTMLFormControlsCollection.h:
     29        * html/RadioNodeList.h:
     30
    1312014-03-29  Antti Koivisto  <antti@apple.com>
    232
  • trunk/Source/WebCore/dom/ChildNodeList.h

    r166460 r166461  
    3636class EmptyNodeList final : public NodeList {
    3737public:
    38     static PassRefPtr<EmptyNodeList> create(Node& owner)
     38    static PassRef<EmptyNodeList> create(Node& owner)
    3939    {
    40         return adoptRef(new EmptyNodeList(owner));
     40        return adoptRef(*new EmptyNodeList(owner));
    4141    }
    4242    virtual ~EmptyNodeList();
     
    5959class ChildNodeList final : public NodeList {
    6060public:
    61     static PassRefPtr<ChildNodeList> create(ContainerNode& parent)
     61    static PassRef<ChildNodeList> create(ContainerNode& parent)
    6262    {
    63         return adoptRef(new ChildNodeList(parent));
     63        return adoptRef(*new ChildNodeList(parent));
    6464    }
    6565
  • trunk/Source/WebCore/dom/ClassNodeList.h

    r166407 r166461  
    4040class ClassNodeList final : public CachedLiveNodeList<ClassNodeList> {
    4141public:
    42     static PassRefPtr<ClassNodeList> create(ContainerNode& rootNode, const String& classNames)
     42    static PassRef<ClassNodeList> create(ContainerNode& rootNode, const String& classNames)
    4343    {
    44         return adoptRef(new ClassNodeList(rootNode, classNames));
     44        return adoptRef(*new ClassNodeList(rootNode, classNames));
    4545    }
    4646
  • trunk/Source/WebCore/dom/NameNodeList.h

    r166407 r166461  
    3434class NameNodeList final : public CachedLiveNodeList<NameNodeList> {
    3535public:
    36     static PassRefPtr<NameNodeList> create(ContainerNode& rootNode, const AtomicString& name)
     36    static PassRef<NameNodeList> create(ContainerNode& rootNode, const AtomicString& name)
    3737    {
    38         return adoptRef(new NameNodeList(rootNode, name));
     38        return adoptRef(*new NameNodeList(rootNode, name));
    3939    }
    4040
  • trunk/Source/WebCore/dom/NodeRareData.h

    r166377 r166461  
    6767    }
    6868
    69     PassRefPtr<ChildNodeList> ensureChildNodeList(ContainerNode& node)
     69    PassRef<ChildNodeList> ensureChildNodeList(ContainerNode& node)
    7070    {
    7171        ASSERT(!m_emptyChildNodeList);
    7272        if (m_childNodeList)
    73             return m_childNodeList;
    74         RefPtr<ChildNodeList> list = ChildNodeList::create(node);
    75         m_childNodeList = list.get();
    76         return list.release();
     73            return *m_childNodeList;
     74        auto list = ChildNodeList::create(node);
     75        m_childNodeList = &list.get();
     76        return list;
    7777    }
    7878
     
    8585    }
    8686
    87     PassRefPtr<EmptyNodeList> ensureEmptyChildNodeList(Node& node)
     87    PassRef<EmptyNodeList> ensureEmptyChildNodeList(Node& node)
    8888    {
    8989        ASSERT(!m_childNodeList);
    9090        if (m_emptyChildNodeList)
    91             return m_emptyChildNodeList;
    92         RefPtr<EmptyNodeList> list = EmptyNodeList::create(node);
    93         m_emptyChildNodeList = list.get();
    94         return list.release();
     91            return *m_emptyChildNodeList;
     92        auto list = EmptyNodeList::create(node);
     93        m_emptyChildNodeList = &list.get();
     94        return list;
    9595    }
    9696
     
    119119
    120120    template<typename T, typename ContainerType>
    121     PassRefPtr<T> addCacheWithAtomicName(ContainerType& container, const AtomicString& name)
     121    PassRef<T> addCacheWithAtomicName(ContainerType& container, const AtomicString& name)
    122122    {
    123123        NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(namedNodeListKey<T>(name), nullptr);
    124124        if (!result.isNewEntry)
    125             return static_cast<T*>(result.iterator->value);
    126 
    127         RefPtr<T> list = T::create(container, name);
    128         result.iterator->value = list.get();
    129         return list.release();
     125            return static_cast<T&>(*result.iterator->value);
     126
     127        auto list = T::create(container, name);
     128        result.iterator->value = &list.get();
     129        return list;
    130130    }
    131131
    132132    template<typename T>
    133     PassRefPtr<T> addCacheWithName(ContainerNode& node, const String& name)
     133    PassRef<T> addCacheWithName(ContainerNode& node, const String& name)
    134134    {
    135135        NodeListNameCacheMap::AddResult result = m_nameCaches.add(namedNodeListKey<T>(name), nullptr);
    136136        if (!result.isNewEntry)
    137             return static_cast<T*>(result.iterator->value);
    138 
    139         RefPtr<T> list = T::create(node, name);
    140         result.iterator->value = list.get();
    141         return list.release();
    142     }
    143 
    144     PassRefPtr<TagNodeList> addCacheWithQualifiedName(ContainerNode& node, const AtomicString& namespaceURI, const AtomicString& localName)
     137            return static_cast<T&>(*result.iterator->value);
     138
     139        auto list = T::create(node, name);
     140        result.iterator->value = &list.get();
     141        return list;
     142    }
     143
     144    PassRef<TagNodeList> addCacheWithQualifiedName(ContainerNode& node, const AtomicString& namespaceURI, const AtomicString& localName)
    145145    {
    146146        QualifiedName name(nullAtom, localName, namespaceURI);
    147147        TagNodeListCacheNS::AddResult result = m_tagNodeListCacheNS.add(name, nullptr);
    148148        if (!result.isNewEntry)
    149             return result.iterator->value;
    150 
    151         RefPtr<TagNodeList> list = TagNodeList::create(node, namespaceURI, localName);
    152         result.iterator->value = list.get();
    153         return list.release();
     149            return *result.iterator->value;
     150
     151        auto list = TagNodeList::create(node, namespaceURI, localName);
     152        result.iterator->value = &list.get();
     153        return list;
    154154    }
    155155
    156156    template<typename T, typename ContainerType>
    157     PassRefPtr<T> addCachedCollection(ContainerType& container, CollectionType collectionType, const AtomicString& name)
     157    PassRef<T> addCachedCollection(ContainerType& container, CollectionType collectionType, const AtomicString& name)
    158158    {
    159159        CollectionCacheMap::AddResult result = m_cachedCollections.add(namedCollectionKey(collectionType, name), nullptr);
    160160        if (!result.isNewEntry)
    161             return static_cast<T*>(result.iterator->value);
    162 
    163         RefPtr<T> list = T::create(container, collectionType, name);
    164         result.iterator->value = list.get();
    165         return list.release();
     161            return static_cast<T&>(*result.iterator->value);
     162
     163        auto list = T::create(container, collectionType, name);
     164        result.iterator->value = &list.get();
     165        return list;
    166166    }
    167167
    168168    template<typename T, typename ContainerType>
    169     PassRefPtr<T> addCachedCollection(ContainerType& container, CollectionType collectionType)
     169    PassRef<T> addCachedCollection(ContainerType& container, CollectionType collectionType)
    170170    {
    171171        CollectionCacheMap::AddResult result = m_cachedCollections.add(namedCollectionKey(collectionType, starAtom), nullptr);
    172172        if (!result.isNewEntry)
    173             return static_cast<T*>(result.iterator->value);
    174 
    175         RefPtr<T> list = T::create(container, collectionType);
    176         result.iterator->value = list.get();
    177         return list.release();
     173            return static_cast<T&>(*result.iterator->value);
     174
     175        auto list = T::create(container, collectionType);
     176        result.iterator->value = &list.get();
     177        return list;
    178178    }
    179179
  • trunk/Source/WebCore/dom/TagNodeList.h

    r166407 r166461  
    3434class TagNodeList final : public CachedLiveNodeList<TagNodeList> {
    3535public:
    36     static PassRefPtr<TagNodeList> create(ContainerNode& rootNode, const AtomicString& namespaceURI, const AtomicString& localName)
     36    static PassRef<TagNodeList> create(ContainerNode& rootNode, const AtomicString& namespaceURI, const AtomicString& localName)
    3737    {
    3838        ASSERT(namespaceURI != starAtom);
    39         return adoptRef(new TagNodeList(rootNode, namespaceURI, localName));
     39        return adoptRef(*new TagNodeList(rootNode, namespaceURI, localName));
    4040    }
    4141
    42     static PassRefPtr<TagNodeList> create(ContainerNode& rootNode, const AtomicString& localName)
     42    static PassRef<TagNodeList> create(ContainerNode& rootNode, const AtomicString& localName)
    4343    {
    44         return adoptRef(new TagNodeList(rootNode, starAtom, localName));
     44        return adoptRef(*new TagNodeList(rootNode, starAtom, localName));
    4545    }
    4646
     
    6868class HTMLTagNodeList final : public CachedLiveNodeList<HTMLTagNodeList> {
    6969public:
    70     static PassRefPtr<HTMLTagNodeList> create(ContainerNode& rootNode, const AtomicString& localName)
     70    static PassRef<HTMLTagNodeList> create(ContainerNode& rootNode, const AtomicString& localName)
    7171    {
    72         return adoptRef(new HTMLTagNodeList(rootNode, localName));
     72        return adoptRef(*new HTMLTagNodeList(rootNode, localName));
    7373    }
    7474
  • trunk/Source/WebCore/html/HTMLCollection.cpp

    r166460 r166461  
    146146}
    147147
    148 PassRefPtr<HTMLCollection> HTMLCollection::create(ContainerNode& base, CollectionType type)
    149 {
    150     return adoptRef(new HTMLCollection(base, type));
     148PassRef<HTMLCollection> HTMLCollection::create(ContainerNode& base, CollectionType type)
     149{
     150    return adoptRef(*new HTMLCollection(base, type));
    151151}
    152152
  • trunk/Source/WebCore/html/HTMLCollection.h

    r166460 r166461  
    8787class HTMLCollection : public ScriptWrappable, public RefCounted<HTMLCollection> {
    8888public:
    89     static PassRefPtr<HTMLCollection> create(ContainerNode& base, CollectionType);
     89    static PassRef<HTMLCollection> create(ContainerNode& base, CollectionType);
    9090    virtual ~HTMLCollection();
    9191
  • trunk/Source/WebCore/html/HTMLFormControlsCollection.cpp

    r165103 r166461  
    4444}
    4545
    46 PassRefPtr<HTMLFormControlsCollection> HTMLFormControlsCollection::create(ContainerNode& ownerNode, CollectionType)
     46PassRef<HTMLFormControlsCollection> HTMLFormControlsCollection::create(ContainerNode& ownerNode, CollectionType)
    4747{
    48     return adoptRef(new HTMLFormControlsCollection(ownerNode));
     48    return adoptRef(*new HTMLFormControlsCollection(ownerNode));
    4949}
    5050
  • trunk/Source/WebCore/html/HTMLFormControlsCollection.h

    r165103 r166461  
    3838class HTMLFormControlsCollection : public HTMLCollection {
    3939public:
    40     static PassRefPtr<HTMLFormControlsCollection> create(ContainerNode&, CollectionType);
     40    static PassRef<HTMLFormControlsCollection> create(ContainerNode&, CollectionType);
    4141
    4242    virtual ~HTMLFormControlsCollection();
  • trunk/Source/WebCore/html/RadioNodeList.h

    r166407 r166461  
    3636class RadioNodeList final : public CachedLiveNodeList<RadioNodeList> {
    3737public:
    38     static PassRefPtr<RadioNodeList> create(ContainerNode& rootNode, const AtomicString& name)
     38    static PassRef<RadioNodeList> create(ContainerNode& rootNode, const AtomicString& name)
    3939    {
    40         return adoptRef(new RadioNodeList(rootNode, name));
     40        return adoptRef(*new RadioNodeList(rootNode, name));
    4141    }
    4242
Note: See TracChangeset for help on using the changeset viewer.