Changeset 45620 in webkit
- Timestamp:
- Jul 7, 2009 10:38:20 PM (15 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r45618 r45620 1 2009-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 1 29 2009-07-07 Simon Fraser <simon.fraser@apple.com> 2 30 -
trunk/WebCore/dom/DynamicNodeList.cpp
r37037 r45620 31 31 DynamicNodeList::DynamicNodeList(PassRefPtr<Node> rootNode) 32 32 : m_rootNode(rootNode) 33 , m_caches( new Caches)33 , m_caches(Caches::create()) 34 34 , m_ownsCaches(true) 35 35 { … … 43 43 { 44 44 m_rootNode->registerDynamicNodeList(this); 45 ++caches->refCount;46 45 } 47 46 … … 49 48 { 50 49 m_rootNode->unregisterDynamicNodeList(this); 51 if (m_ownsCaches)52 delete m_caches;53 else54 --m_caches->refCount;55 50 } 56 51 … … 159 154 , isLengthCacheValid(false) 160 155 , isItemCacheValid(false) 161 , refCount(0)162 156 { 157 } 158 159 PassRefPtr<DynamicNodeList::Caches> DynamicNodeList::Caches::create() 160 { 161 return adoptRef(new Caches()); 163 162 } 164 163 -
trunk/WebCore/dom/DynamicNodeList.h
r37037 r45620 38 38 class DynamicNodeList : public NodeList { 39 39 public: 40 struct Caches {41 Caches();40 struct Caches : RefCounted<Caches>{ 41 static PassRefPtr<Caches> create(); 42 42 void reset(); 43 43 … … 47 47 bool isLengthCacheValid : 1; 48 48 bool isItemCacheValid : 1; 49 unsigned refCount; 49 protected: 50 Caches(); 50 51 }; 51 52 … … 69 70 70 71 RefPtr<Node> m_rootNode; 71 mutable Caches*m_caches;72 mutable RefPtr<Caches> m_caches; 72 73 bool m_ownsCaches; 73 74 -
trunk/WebCore/dom/Node.cpp
r45251 r45620 518 518 } 519 519 520 return ChildNodeList::create(this, &data->nodeLists()->m_childNodeListCaches);520 return ChildNodeList::create(this, data->nodeLists()->m_childNodeListCaches.get()); 521 521 } 522 522 … … 1501 1501 pair<NodeListsNodeData::TagCacheMap::iterator, bool> result = data->nodeLists()->m_tagNodeListCaches.add(QualifiedName(nullAtom, localNameAtom, namespaceURI), 0); 1502 1502 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()); 1506 1506 } 1507 1507 … … 1516 1516 pair<NodeListsNodeData::CacheMap::iterator, bool> result = data->nodeLists()->m_nameNodeListCaches.add(elementName, 0); 1517 1517 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()); 1521 1521 } 1522 1522 … … 1531 1531 pair<NodeListsNodeData::CacheMap::iterator, bool> result = data->nodeLists()->m_classNodeListCaches.add(classNames, 0); 1532 1532 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()); 1536 1536 } 1537 1537 … … 2186 2186 void NodeListsNodeData::invalidateCaches() 2187 2187 { 2188 m_childNodeListCaches .reset();2188 m_childNodeListCaches->reset(); 2189 2189 TagCacheMap::const_iterator tagCachesEnd = m_tagNodeListCaches.end(); 2190 2190 for (TagCacheMap::const_iterator it = m_tagNodeListCaches.begin(); it != tagCachesEnd; ++it) … … 2209 2209 return false; 2210 2210 2211 if (m_childNodeListCaches .refCount)2211 if (m_childNodeListCaches->refCount()) 2212 2212 return false; 2213 2213 2214 2214 TagCacheMap::const_iterator tagCachesEnd = m_tagNodeListCaches.end(); 2215 2215 for (TagCacheMap::const_iterator it = m_tagNodeListCaches.begin(); it != tagCachesEnd; ++it) { 2216 if (it->second->refCount )2216 if (it->second->refCount()) 2217 2217 return false; 2218 2218 } … … 2220 2220 CacheMap::const_iterator classCachesEnd = m_classNodeListCaches.end(); 2221 2221 for (CacheMap::const_iterator it = m_classNodeListCaches.begin(); it != classCachesEnd; ++it) { 2222 if (it->second->refCount )2222 if (it->second->refCount()) 2223 2223 return false; 2224 2224 } … … 2226 2226 CacheMap::const_iterator nameCachesEnd = m_nameNodeListCaches.end(); 2227 2227 for (CacheMap::const_iterator it = m_nameNodeListCaches.begin(); it != nameCachesEnd; ++it) { 2228 if (it->second->refCount )2228 if (it->second->refCount()) 2229 2229 return false; 2230 2230 } -
trunk/WebCore/dom/NodeRareData.h
r44096 r45620 38 38 NodeListSet m_listsWithCaches; 39 39 40 DynamicNodeList::Cachesm_childNodeListCaches;40 RefPtr<DynamicNodeList::Caches> m_childNodeListCaches; 41 41 42 typedef HashMap<String, DynamicNodeList::Caches*> CacheMap;42 typedef HashMap<String, RefPtr<DynamicNodeList::Caches> > CacheMap; 43 43 CacheMap m_classNodeListCaches; 44 44 CacheMap m_nameNodeListCaches; 45 45 46 typedef HashMap<QualifiedName, DynamicNodeList::Caches*> TagCacheMap;46 typedef HashMap<QualifiedName, RefPtr<DynamicNodeList::Caches> > TagCacheMap; 47 47 TagCacheMap m_tagNodeListCaches; 48 48 49 49 static PassOwnPtr<NodeListsNodeData> create() { 50 50 return new NodeListsNodeData; 51 }52 53 ~NodeListsNodeData()54 {55 deleteAllValues(m_classNodeListCaches);56 deleteAllValues(m_nameNodeListCaches);57 deleteAllValues(m_tagNodeListCaches);58 51 } 59 52 … … 63 56 64 57 private: 65 NodeListsNodeData() { } 58 NodeListsNodeData() 59 : m_childNodeListCaches(DynamicNodeList::Caches::create()) 60 { 61 } 66 62 }; 67 63
Note: See TracChangeset
for help on using the changeset viewer.