Changeset 45620 in webkit


Ignore:
Timestamp:
Jul 7, 2009 10:38:20 PM (15 years ago)
Author:
oliver@apple.com
Message:

Reduce complexity of lifetime management in DynamicNodeList caches
<https://bugs.webkit.org/show_bug.cgi?id=27068>

Reviewed by Maciej Stachowiak

Switch the Cache object used by DynamicNodeList into a normal
refcounted object rather than having a weird flag controlled
refcounting system, where positive refcount did not automatically
imply the cache object would actually still be live.

Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r45618 r45620  
     12009-07-07  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Maciej Stachowiak.
     4
     5        Reduce complexity of lifetime management in DynamicNodeList caches
     6        <https://bugs.webkit.org/show_bug.cgi?id=27068>
     7
     8        Switch the Cache object used by DynamicNodeList into a normal
     9        refcounted object rather than having a weird flag controlled
     10        refcounting system, where positive refcount did not automatically
     11        imply the cache object would actually still be live.
     12
     13        * dom/DynamicNodeList.cpp:
     14        (WebCore::DynamicNodeList::DynamicNodeList):
     15        (WebCore::DynamicNodeList::~DynamicNodeList):
     16        (WebCore::DynamicNodeList::Caches::Caches):
     17        (WebCore::DynamicNodeList::Caches::create):
     18        * dom/DynamicNodeList.h:
     19        * dom/Node.cpp:
     20        (WebCore::Node::childNodes):
     21        (WebCore::Node::getElementsByTagNameNS):
     22        (WebCore::Node::getElementsByName):
     23        (WebCore::Node::getElementsByClassName):
     24        (WebCore::NodeListsNodeData::invalidateCaches):
     25        (WebCore::NodeListsNodeData::isEmpty):
     26        * dom/NodeRareData.h:
     27        (WebCore::NodeListsNodeData::NodeListsNodeData):
     28
    1292009-07-07  Simon Fraser  <simon.fraser@apple.com>
    230
  • trunk/WebCore/dom/DynamicNodeList.cpp

    r37037 r45620  
    3131DynamicNodeList::DynamicNodeList(PassRefPtr<Node> rootNode)
    3232    : m_rootNode(rootNode)
    33     , m_caches(new Caches)
     33    , m_caches(Caches::create())
    3434    , m_ownsCaches(true)
    3535{
     
    4343{
    4444    m_rootNode->registerDynamicNodeList(this);
    45     ++caches->refCount;
    4645}   
    4746
     
    4948{
    5049    m_rootNode->unregisterDynamicNodeList(this);
    51     if (m_ownsCaches)
    52         delete m_caches;
    53     else
    54         --m_caches->refCount;
    5550}
    5651
     
    159154    , isLengthCacheValid(false)
    160155    , isItemCacheValid(false)
    161     , refCount(0)
    162156{
     157}
     158
     159PassRefPtr<DynamicNodeList::Caches> DynamicNodeList::Caches::create()
     160{
     161    return adoptRef(new Caches());
    163162}
    164163
  • trunk/WebCore/dom/DynamicNodeList.h

    r37037 r45620  
    3838    class DynamicNodeList : public NodeList {
    3939    public:
    40         struct Caches {
    41             Caches();
     40        struct Caches : RefCounted<Caches>{
     41            static PassRefPtr<Caches> create();
    4242            void reset();
    4343
     
    4747            bool isLengthCacheValid : 1;
    4848            bool isItemCacheValid : 1;
    49             unsigned refCount;
     49        protected:
     50            Caches();
    5051        };
    5152
     
    6970
    7071        RefPtr<Node> m_rootNode;
    71         mutable Caches* m_caches;
     72        mutable RefPtr<Caches> m_caches;
    7273        bool m_ownsCaches;
    7374
  • trunk/WebCore/dom/Node.cpp

    r45251 r45620  
    518518    }
    519519
    520     return ChildNodeList::create(this, &data->nodeLists()->m_childNodeListCaches);
     520    return ChildNodeList::create(this, data->nodeLists()->m_childNodeListCaches.get());
    521521}
    522522
     
    15011501    pair<NodeListsNodeData::TagCacheMap::iterator, bool> result = data->nodeLists()->m_tagNodeListCaches.add(QualifiedName(nullAtom, localNameAtom, namespaceURI), 0);
    15021502    if (result.second)
    1503         result.first->second = new DynamicNodeList::Caches;
    1504    
    1505     return TagNodeList::create(this, namespaceURI.isEmpty() ? nullAtom : namespaceURI, localNameAtom, result.first->second);
     1503        result.first->second = DynamicNodeList::Caches::create();
     1504   
     1505    return TagNodeList::create(this, namespaceURI.isEmpty() ? nullAtom : namespaceURI, localNameAtom, result.first->second.get());
    15061506}
    15071507
     
    15161516    pair<NodeListsNodeData::CacheMap::iterator, bool> result = data->nodeLists()->m_nameNodeListCaches.add(elementName, 0);
    15171517    if (result.second)
    1518         result.first->second = new DynamicNodeList::Caches;
    1519    
    1520     return NameNodeList::create(this, elementName, result.first->second);
     1518        result.first->second = DynamicNodeList::Caches::create();
     1519   
     1520    return NameNodeList::create(this, elementName, result.first->second.get());
    15211521}
    15221522
     
    15311531    pair<NodeListsNodeData::CacheMap::iterator, bool> result = data->nodeLists()->m_classNodeListCaches.add(classNames, 0);
    15321532    if (result.second)
    1533         result.first->second = new DynamicNodeList::Caches;
    1534    
    1535     return ClassNodeList::create(this, classNames, result.first->second);
     1533        result.first->second = DynamicNodeList::Caches::create();
     1534   
     1535    return ClassNodeList::create(this, classNames, result.first->second.get());
    15361536}
    15371537
     
    21862186void NodeListsNodeData::invalidateCaches()
    21872187{
    2188     m_childNodeListCaches.reset();
     2188    m_childNodeListCaches->reset();
    21892189    TagCacheMap::const_iterator tagCachesEnd = m_tagNodeListCaches.end();
    21902190    for (TagCacheMap::const_iterator it = m_tagNodeListCaches.begin(); it != tagCachesEnd; ++it)
     
    22092209        return false;
    22102210
    2211     if (m_childNodeListCaches.refCount)
     2211    if (m_childNodeListCaches->refCount())
    22122212        return false;
    22132213   
    22142214    TagCacheMap::const_iterator tagCachesEnd = m_tagNodeListCaches.end();
    22152215    for (TagCacheMap::const_iterator it = m_tagNodeListCaches.begin(); it != tagCachesEnd; ++it) {
    2216         if (it->second->refCount)
     2216        if (it->second->refCount())
    22172217            return false;
    22182218    }
     
    22202220    CacheMap::const_iterator classCachesEnd = m_classNodeListCaches.end();
    22212221    for (CacheMap::const_iterator it = m_classNodeListCaches.begin(); it != classCachesEnd; ++it) {
    2222         if (it->second->refCount)
     2222        if (it->second->refCount())
    22232223            return false;
    22242224    }
     
    22262226    CacheMap::const_iterator nameCachesEnd = m_nameNodeListCaches.end();
    22272227    for (CacheMap::const_iterator it = m_nameNodeListCaches.begin(); it != nameCachesEnd; ++it) {
    2228         if (it->second->refCount)
     2228        if (it->second->refCount())
    22292229            return false;
    22302230    }
  • trunk/WebCore/dom/NodeRareData.h

    r44096 r45620  
    3838    NodeListSet m_listsWithCaches;
    3939   
    40     DynamicNodeList::Caches m_childNodeListCaches;
     40    RefPtr<DynamicNodeList::Caches> m_childNodeListCaches;
    4141   
    42     typedef HashMap<String, DynamicNodeList::Caches*> CacheMap;
     42    typedef HashMap<String, RefPtr<DynamicNodeList::Caches> > CacheMap;
    4343    CacheMap m_classNodeListCaches;
    4444    CacheMap m_nameNodeListCaches;
    4545   
    46     typedef HashMap<QualifiedName, DynamicNodeList::Caches*> TagCacheMap;
     46    typedef HashMap<QualifiedName, RefPtr<DynamicNodeList::Caches> > TagCacheMap;
    4747    TagCacheMap m_tagNodeListCaches;
    4848
    4949    static PassOwnPtr<NodeListsNodeData> create() {
    5050        return new NodeListsNodeData;
    51     }
    52 
    53     ~NodeListsNodeData()
    54     {
    55         deleteAllValues(m_classNodeListCaches);
    56         deleteAllValues(m_nameNodeListCaches);
    57         deleteAllValues(m_tagNodeListCaches);
    5851    }
    5952   
     
    6356
    6457private:
    65     NodeListsNodeData() { }
     58    NodeListsNodeData()
     59        : m_childNodeListCaches(DynamicNodeList::Caches::create())
     60    {
     61    }
    6662};
    6763   
Note: See TracChangeset for help on using the changeset viewer.