Skip to content

Commit 787cfe9

Browse files
committed
HTMLCollection should use DynamicNodeList's invalidation model
https://bugs.webkit.org/show_bug.cgi?id=90326 Reviewed by Anders Carlsson. Make HTMLCollection invalidated upon attribute and children changes instead of invalidating it on demand by comparing DOM tree versions. Node that HTMLCollections owned by Document are invalidated with other document-rooted node lists in m_listsInvalidatedAtDocument for simplicity although this mechanism is normally used for node lists owned by a non-Document node that contains nodes outside of its subtree. ItemProperties and FormControls are more "traditional" users of the mechanism. Also, merged DynamicNodeList::invalidateCache and HTMLCollection::invalidateCache. * dom/Document.cpp: (WebCore::Document::registerNodeListCache): Renamed. No longer takes NodeListInvalidationType or NodeListRootType since they can be obtained from the cache base. Increment the node list counter for InvalidateOnIdNameAttrChange when a HTMLCollection is passed in since all HTMLCollections need to be invalidated on id or name content attribute changes due to named getters. (WebCore::Document::unregisterNodeListCache): Ditto. (WebCore::shouldInvalidateNodeListForType): (WebCore::Document::shouldInvalidateNodeListCaches): (WebCore::Document::clearNodeListCaches): * dom/Document.h: (WebCore): Added InvalidateOnIdNameAttrChange, InvalidateOnHRefAttrChange, and InvalidateOnAnyAttrChange. (Document): * dom/DynamicNodeList.cpp: (WebCore::DynamicNodeListCacheBase::invalidateCache): Added. Invalidates caches of both DynamicNodeList and HTMLCollection. We can't afford to use virtual function calls here because this function is called on all node lists and HTML collections owned by ancestors of an element under which a node is added, removed, or its attributes are changed. (WebCore): * dom/DynamicNodeList.h: (WebCore::DynamicNodeListCacheBase::DynamicNodeListCacheBase): Initializes member variables directly instead of calling clearCache now that DynamicNodeListCacheBase::invalidateCache has become polymorphic. (DynamicNodeListCacheBase): Increased the number of bits for m_invalidationType since we now have 9 invalidation types. (WebCore::DynamicSubtreeNodeList::~DynamicSubtreeNodeList): (WebCore::DynamicSubtreeNodeList::DynamicSubtreeNodeList): * dom/ElementRareData.h: (ElementRareData): (WebCore::ElementRareData::clearHTMLCollectionCaches): Added. (WebCore::ElementRareData::adoptTreeScope): Added; similar to NodeRareData::adoptTreeScope. * dom/Node.cpp: (WebCore::Node::invalidateNodeListsCacheAfterAttributeChanged): Clears HTML collection caches as well as node list caches. (WebCore::Node::invalidateNodeListsCacheAfterChildrenChanged): Ditto. * dom/NodeRareData.h: (WebCore::NodeListsNodeData::adoptTreeScope): * dom/TreeScopeAdopter.cpp: (WebCore::TreeScopeAdopter::moveTreeToNewScope): Calls ElementRareData's adoptTreeScope as well as NodeRareData's. * html/HTMLAllCollection.cpp: (WebCore::HTMLAllCollection::namedItemWithIndex): * html/HTMLCollection.cpp: (WebCore::rootTypeFromCollectionType): Added. As mentioned above, treat all Document-owned HTML collection as if rooted at document for convenience. (WebCore::invalidationTypeExcludingIdAndNameAttributes): Added. Since all HTML collection requires invalidation on id and name content attribute changes, which is taken care by the special logic in Document::registerNodeListCache, exclude those two attributes from consideration. (WebCore::HTMLCollection::HTMLCollection): Calls Document::registerNodeListCache. (WebCore::HTMLCollection::~HTMLCollection): Calls Document::unregisterNodeListCache. (WebCore::HTMLCollection::length): (WebCore::HTMLCollection::item): (WebCore::HTMLCollection::namedItem): (WebCore::HTMLCollection::updateNameCache): * html/HTMLCollection.h: (WebCore::HTMLCollectionCacheBase::HTMLCollectionCacheBase): (HTMLCollectionCacheBase): Removed m_cacheTreeVersion and clearCache since they're no longer used. (HTMLCollection): * html/HTMLFormCollection.cpp: (WebCore::HTMLFormCollection::namedItem): (WebCore::HTMLFormCollection::updateNameCache): * html/HTMLOptionsCollection.h: (HTMLOptionsCollection): * html/HTMLPropertiesCollection.cpp: (WebCore::HTMLPropertiesCollection::updateNameCache): * html/HTMLPropertiesCollection.h: (WebCore::HTMLPropertiesCollection::invalidateCache): Canonical link: https://commits.webkit.org/109093@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@122621 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 556eb38 commit 787cfe9

16 files changed

Lines changed: 288 additions & 116 deletions

Source/WebCore/ChangeLog

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,84 @@
1+
2012-07-13 Ryosuke Niwa <rniwa@webkit.org>
2+
3+
HTMLCollection should use DynamicNodeList's invalidation model
4+
https://bugs.webkit.org/show_bug.cgi?id=90326
5+
6+
Reviewed by Anders Carlsson.
7+
8+
Make HTMLCollection invalidated upon attribute and children changes instead of invalidating it on demand
9+
by comparing DOM tree versions. Node that HTMLCollections owned by Document are invalidated with other
10+
document-rooted node lists in m_listsInvalidatedAtDocument for simplicity although this mechanism is
11+
normally used for node lists owned by a non-Document node that contains nodes outside of its subtree.
12+
ItemProperties and FormControls are more "traditional" users of the mechanism.
13+
14+
Also, merged DynamicNodeList::invalidateCache and HTMLCollection::invalidateCache.
15+
16+
* dom/Document.cpp:
17+
(WebCore::Document::registerNodeListCache): Renamed. No longer takes NodeListInvalidationType or
18+
NodeListRootType since they can be obtained from the cache base. Increment the node list counter for
19+
InvalidateOnIdNameAttrChange when a HTMLCollection is passed in since all HTMLCollections need to be
20+
invalidated on id or name content attribute changes due to named getters.
21+
(WebCore::Document::unregisterNodeListCache): Ditto.
22+
(WebCore::shouldInvalidateNodeListForType):
23+
(WebCore::Document::shouldInvalidateNodeListCaches):
24+
(WebCore::Document::clearNodeListCaches):
25+
* dom/Document.h:
26+
(WebCore): Added InvalidateOnIdNameAttrChange, InvalidateOnHRefAttrChange, and InvalidateOnAnyAttrChange.
27+
(Document):
28+
* dom/DynamicNodeList.cpp:
29+
(WebCore::DynamicNodeListCacheBase::invalidateCache): Added. Invalidates caches of both DynamicNodeList
30+
and HTMLCollection. We can't afford to use virtual function calls here because this function is called on
31+
all node lists and HTML collections owned by ancestors of an element under which a node is added, removed,
32+
or its attributes are changed.
33+
(WebCore):
34+
* dom/DynamicNodeList.h:
35+
(WebCore::DynamicNodeListCacheBase::DynamicNodeListCacheBase): Initializes member variables directly
36+
instead of calling clearCache now that DynamicNodeListCacheBase::invalidateCache has become polymorphic.
37+
(DynamicNodeListCacheBase): Increased the number of bits for m_invalidationType since we now have 9
38+
invalidation types.
39+
(WebCore::DynamicSubtreeNodeList::~DynamicSubtreeNodeList):
40+
(WebCore::DynamicSubtreeNodeList::DynamicSubtreeNodeList):
41+
* dom/ElementRareData.h:
42+
(ElementRareData):
43+
(WebCore::ElementRareData::clearHTMLCollectionCaches): Added.
44+
(WebCore::ElementRareData::adoptTreeScope): Added; similar to NodeRareData::adoptTreeScope.
45+
* dom/Node.cpp:
46+
(WebCore::Node::invalidateNodeListsCacheAfterAttributeChanged): Clears HTML collection caches as well as
47+
node list caches.
48+
(WebCore::Node::invalidateNodeListsCacheAfterChildrenChanged): Ditto.
49+
* dom/NodeRareData.h:
50+
(WebCore::NodeListsNodeData::adoptTreeScope):
51+
* dom/TreeScopeAdopter.cpp:
52+
(WebCore::TreeScopeAdopter::moveTreeToNewScope): Calls ElementRareData's adoptTreeScope as well as
53+
NodeRareData's.
54+
* html/HTMLAllCollection.cpp:
55+
(WebCore::HTMLAllCollection::namedItemWithIndex):
56+
* html/HTMLCollection.cpp:
57+
(WebCore::rootTypeFromCollectionType): Added. As mentioned above, treat all Document-owned HTML collection
58+
as if rooted at document for convenience.
59+
(WebCore::invalidationTypeExcludingIdAndNameAttributes): Added. Since all HTML collection requires
60+
invalidation on id and name content attribute changes, which is taken care by the special logic in
61+
Document::registerNodeListCache, exclude those two attributes from consideration.
62+
(WebCore::HTMLCollection::HTMLCollection): Calls Document::registerNodeListCache.
63+
(WebCore::HTMLCollection::~HTMLCollection): Calls Document::unregisterNodeListCache.
64+
(WebCore::HTMLCollection::length):
65+
(WebCore::HTMLCollection::item):
66+
(WebCore::HTMLCollection::namedItem):
67+
(WebCore::HTMLCollection::updateNameCache):
68+
* html/HTMLCollection.h:
69+
(WebCore::HTMLCollectionCacheBase::HTMLCollectionCacheBase):
70+
(HTMLCollectionCacheBase): Removed m_cacheTreeVersion and clearCache since they're no longer used.
71+
(HTMLCollection):
72+
* html/HTMLFormCollection.cpp:
73+
(WebCore::HTMLFormCollection::namedItem):
74+
(WebCore::HTMLFormCollection::updateNameCache):
75+
* html/HTMLOptionsCollection.h:
76+
(HTMLOptionsCollection):
77+
* html/HTMLPropertiesCollection.cpp:
78+
(WebCore::HTMLPropertiesCollection::updateNameCache):
79+
* html/HTMLPropertiesCollection.h:
80+
(WebCore::HTMLPropertiesCollection::invalidateCache):
81+
182
2012-07-13 Shawn Singh <shawnsingh@chromium.org>
283

384
[chromium] Remove incorrect debug assertion in LayerRendererChromium.cpp

Source/WebCore/dom/Document.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3861,17 +3861,21 @@ void Document::setCSSTarget(Element* n)
38613861
n->setNeedsStyleRecalc();
38623862
}
38633863

3864-
void Document::registerDynamicSubtreeNodeList(DynamicSubtreeNodeList* list, NodeListRootType rootType, NodeListInvalidationType invalidationType)
3864+
void Document::registerNodeListCache(DynamicNodeListCacheBase* list)
38653865
{
3866-
m_nodeListCounts[invalidationType]++;
3867-
if (rootType == NodeListIsRootedAtDocument)
3866+
if (list->type() != InvalidCollectionType)
3867+
m_nodeListCounts[InvalidateOnIdNameAttrChange]++;
3868+
m_nodeListCounts[list->invalidationType()]++;
3869+
if (list->rootType() == NodeListIsRootedAtDocument)
38683870
m_listsInvalidatedAtDocument.add(list);
38693871
}
38703872

3871-
void Document::unregisterDynamicSubtreeNodeList(DynamicSubtreeNodeList* list, NodeListRootType rootType, NodeListInvalidationType invalidationType)
3873+
void Document::unregisterNodeListCache(DynamicNodeListCacheBase* list)
38723874
{
3873-
m_nodeListCounts[invalidationType]--;
3874-
if (rootType == NodeListIsRootedAtDocument) {
3875+
if (list->type() != InvalidCollectionType)
3876+
m_nodeListCounts[InvalidateOnIdNameAttrChange]--;
3877+
m_nodeListCounts[list->invalidationType()]--;
3878+
if (list->rootType() == NodeListIsRootedAtDocument) {
38753879
ASSERT(m_listsInvalidatedAtDocument.contains(list));
38763880
m_listsInvalidatedAtDocument.remove(list);
38773881
}
@@ -3884,22 +3888,28 @@ static ALWAYS_INLINE bool shouldInvalidateNodeListForType(NodeListInvalidationTy
38843888
return attrName == classAttr;
38853889
case InvalidateOnNameAttrChange:
38863890
return attrName == nameAttr;
3891+
case InvalidateOnIdNameAttrChange:
3892+
return attrName == idAttr || attrName == nameAttr;
38873893
case InvalidateOnForAttrChange:
38883894
return attrName == forAttr;
38893895
case InvalidateForFormControls:
38903896
return attrName == nameAttr || attrName == idAttr || attrName == forAttr || attrName == typeAttr;
3897+
case InvalidateOnHRefAttrChange:
3898+
return attrName == hrefAttr;
38913899
case InvalidateOnItemAttrChange:
38923900
#if ENABLE(MICRODATA)
38933901
return attrName == itemscopeAttr || attrName == itempropAttr || attrName == itemtypeAttr;
38943902
#endif // Intentionally fall through
38953903
case DoNotInvalidateOnAttributeChanges:
38963904
ASSERT_NOT_REACHED();
38973905
return false;
3906+
case InvalidateOnAnyAttrChange:
3907+
return true;
38983908
}
38993909
return false;
39003910
}
39013911

3902-
bool Document::shouldInvalidateDynamicSubtreeNodeList(const QualifiedName* attrName) const
3912+
bool Document::shouldInvalidateNodeListCaches(const QualifiedName* attrName) const
39033913
{
39043914
if (attrName) {
39053915
for (int type = DoNotInvalidateOnAttributeChanges + 1; type < numNodeListInvalidationTypes; type++) {
@@ -3919,8 +3929,8 @@ bool Document::shouldInvalidateDynamicSubtreeNodeList(const QualifiedName* attrN
39193929

39203930
void Document::clearNodeListCaches()
39213931
{
3922-
HashSet<DynamicSubtreeNodeList*>::iterator end = m_listsInvalidatedAtDocument.end();
3923-
for (HashSet<DynamicSubtreeNodeList*>::iterator it = m_listsInvalidatedAtDocument.begin(); it != end; ++it)
3932+
HashSet<DynamicNodeListCacheBase*>::iterator end = m_listsInvalidatedAtDocument.end();
3933+
for (HashSet<DynamicNodeListCacheBase*>::iterator it = m_listsInvalidatedAtDocument.begin(); it != end; ++it)
39243934
(*it)->invalidateCache();
39253935
}
39263936

Source/WebCore/dom/Document.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class DocumentMarkerController;
7979
class DocumentParser;
8080
class DocumentType;
8181
class DocumentWeakReference;
82+
class DynamicNodeListCacheBase;
8283
class EditingText;
8384
class Element;
8485
class EntityReference;
@@ -187,20 +188,18 @@ enum PageshowEventPersistence {
187188

188189
enum StyleResolverUpdateFlag { RecalcStyleImmediately, DeferRecalcStyle, RecalcStyleIfNeeded };
189190

190-
enum NodeListRootType {
191-
NodeListIsRootedAtNode,
192-
NodeListIsRootedAtDocument,
193-
};
194-
195191
enum NodeListInvalidationType {
196192
DoNotInvalidateOnAttributeChanges = 0,
197193
InvalidateOnClassAttrChange,
194+
InvalidateOnIdNameAttrChange,
198195
InvalidateOnNameAttrChange,
199196
InvalidateOnForAttrChange,
200197
InvalidateForFormControls,
198+
InvalidateOnHRefAttrChange,
201199
InvalidateOnItemAttrChange,
200+
InvalidateOnAnyAttrChange,
202201
};
203-
const int numNodeListInvalidationTypes = InvalidateOnItemAttrChange + 1;
202+
const int numNodeListInvalidationTypes = InvalidateOnAnyAttrChange + 1;
204203

205204
class Document : public ContainerNode, public TreeScope, public ScriptExecutionContext {
206205
public:
@@ -736,9 +735,9 @@ class Document : public ContainerNode, public TreeScope, public ScriptExecutionC
736735
bool isPendingStyleRecalc() const;
737736
void styleRecalcTimerFired(Timer<Document>*);
738737

739-
void registerDynamicSubtreeNodeList(DynamicSubtreeNodeList*, NodeListRootType, NodeListInvalidationType);
740-
void unregisterDynamicSubtreeNodeList(DynamicSubtreeNodeList*, NodeListRootType, NodeListInvalidationType);
741-
bool shouldInvalidateDynamicSubtreeNodeList(const QualifiedName* attrName = 0) const;
738+
void registerNodeListCache(DynamicNodeListCacheBase*);
739+
void unregisterNodeListCache(DynamicNodeListCacheBase*);
740+
bool shouldInvalidateNodeListCaches(const QualifiedName* attrName = 0) const;
742741
void clearNodeListCaches();
743742

744743
void attachNodeIterator(NodeIterator*);
@@ -1422,7 +1421,7 @@ class Document : public ContainerNode, public TreeScope, public ScriptExecutionC
14221421

14231422
InheritedBool m_designMode;
14241423

1425-
HashSet<DynamicSubtreeNodeList*> m_listsInvalidatedAtDocument;
1424+
HashSet<DynamicNodeListCacheBase*> m_listsInvalidatedAtDocument;
14261425
unsigned m_nodeListCounts[numNodeListInvalidationTypes];
14271426

14281427
HTMLCollection* m_collections[NumUnnamedDocumentCachedTypes];

Source/WebCore/dom/DynamicNodeList.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,32 @@
2525

2626
#include "Document.h"
2727
#include "Element.h"
28+
#include "HTMLCollection.h"
29+
#include "HTMLPropertiesCollection.h"
2830

2931
namespace WebCore {
3032

33+
void DynamicNodeListCacheBase::invalidateCache() const
34+
{
35+
m_cachedItem = 0;
36+
m_isLengthCacheValid = false;
37+
m_isItemCacheValid = false;
38+
m_isNameCacheValid = false;
39+
if (type() == InvalidCollectionType)
40+
return;
41+
42+
const HTMLCollectionCacheBase* cacheBase = static_cast<const HTMLCollectionCacheBase*>(this);
43+
cacheBase->m_idCache.clear();
44+
cacheBase->m_nameCache.clear();
45+
cacheBase->m_cachedElementsArrayOffset = 0;
46+
47+
#if ENABLE(MICRODATA)
48+
// FIXME: There should be more generic mechanism to clear caches in subclasses.
49+
if (type() == ItemProperties)
50+
static_cast<const HTMLPropertiesCollection*>(this)->invalidateCache();
51+
#endif
52+
}
53+
3154
unsigned DynamicSubtreeNodeList::length() const
3255
{
3356
if (isLengthCacheValid())

Source/WebCore/dom/DynamicNodeList.h

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,24 @@ namespace WebCore {
3535
class Element;
3636
class Node;
3737

38+
enum NodeListRootType {
39+
NodeListIsRootedAtNode,
40+
NodeListIsRootedAtDocument,
41+
};
42+
3843
class DynamicNodeListCacheBase {
3944
public:
40-
DynamicNodeListCacheBase(NodeListRootType rootType, NodeListInvalidationType invalidationType)
41-
: m_rootedAtDocument(rootType == NodeListIsRootedAtDocument)
45+
DynamicNodeListCacheBase(NodeListRootType rootType, NodeListInvalidationType invalidationType, CollectionType collectionType = InvalidCollectionType)
46+
: m_cachedItem(0)
47+
, m_isLengthCacheValid(false)
48+
, m_isItemCacheValid(false)
49+
, m_rootedAtDocument(rootType == NodeListIsRootedAtDocument)
4250
, m_invalidationType(invalidationType)
43-
, m_collectionType(InvalidCollectionType)
44-
{
45-
ASSERT(m_invalidationType == static_cast<unsigned>(invalidationType));
46-
clearCache();
47-
}
48-
49-
DynamicNodeListCacheBase(CollectionType collectionType)
50-
: m_rootedAtDocument(false) // Ignored
51-
, m_invalidationType(DoNotInvalidateOnAttributeChanges) // Ignored
51+
, m_isNameCacheValid(false)
5252
, m_collectionType(collectionType)
5353
{
54+
ASSERT(m_invalidationType == static_cast<unsigned>(invalidationType));
5455
ASSERT(m_collectionType == static_cast<unsigned>(collectionType));
55-
clearCache();
5656
}
5757

5858
public:
@@ -62,6 +62,8 @@ class DynamicNodeListCacheBase {
6262
ALWAYS_INLINE NodeListInvalidationType invalidationType() const { return static_cast<NodeListInvalidationType>(m_invalidationType); }
6363
ALWAYS_INLINE CollectionType type() const { return static_cast<CollectionType>(m_collectionType); }
6464

65+
void invalidateCache() const;
66+
6567
protected:
6668
ALWAYS_INLINE bool isItemCacheValid() const { return m_isItemCacheValid; }
6769
ALWAYS_INLINE Node* cachedItem() const { return m_cachedItem; }
@@ -85,24 +87,14 @@ class DynamicNodeListCacheBase {
8587
bool hasNameCache() const { return m_isNameCacheValid; }
8688
void setHasNameCache() const { m_isNameCacheValid = true; }
8789

88-
void clearCache() const
89-
{
90-
m_cachedItem = 0;
91-
m_isLengthCacheValid = false;
92-
m_isItemCacheValid = false;
93-
m_isNameCacheValid = false;
94-
}
95-
9690
private:
9791
mutable Node* m_cachedItem;
9892
mutable unsigned m_cachedLength;
9993
mutable unsigned m_cachedItemOffset;
10094
mutable unsigned m_isLengthCacheValid : 1;
10195
mutable unsigned m_isItemCacheValid : 1;
102-
103-
// From DynamicNodeList
10496
const unsigned m_rootedAtDocument : 1;
105-
const unsigned m_invalidationType : 3;
97+
const unsigned m_invalidationType : 4;
10698

10799
// From HTMLCollection
108100
mutable unsigned m_isNameCacheValid : 1;
@@ -133,7 +125,6 @@ class DynamicNodeList : public NodeList, public DynamicNodeListCacheBase {
133125

134126
// Other methods (not part of DOM)
135127
Node* ownerNode() const { return m_ownerNode.get(); }
136-
void invalidateCache() { clearCache(); }
137128

138129
protected:
139130
Node* rootNode() const
@@ -154,7 +145,7 @@ class DynamicSubtreeNodeList : public DynamicNodeList {
154145
public:
155146
virtual ~DynamicSubtreeNodeList()
156147
{
157-
document()->unregisterDynamicSubtreeNodeList(this, rootType(), invalidationType());
148+
document()->unregisterNodeListCache(this);
158149
}
159150
virtual unsigned length() const OVERRIDE;
160151
virtual Node* item(unsigned index) const OVERRIDE;
@@ -163,7 +154,7 @@ class DynamicSubtreeNodeList : public DynamicNodeList {
163154
DynamicSubtreeNodeList(PassRefPtr<Node> node, NodeListInvalidationType invalidationType, NodeListRootType rootType = NodeListIsRootedAtNode)
164155
: DynamicNodeList(node, rootType, invalidationType)
165156
{
166-
document()->registerDynamicSubtreeNodeList(this, rootType, invalidationType);
157+
document()->registerNodeListCache(this);
167158
}
168159

169160
private:

Source/WebCore/dom/ElementRareData.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "DatasetDOMStringMap.h"
2727
#include "Element.h"
2828
#include "ElementShadow.h"
29+
#include "HTMLCollection.h"
2930
#include "NamedNodeMap.h"
3031
#include "NodeRareData.h"
3132
#include <wtf/OwnPtr.h>
@@ -57,13 +58,42 @@ class ElementRareData : public NodeRareData {
5758

5859
return (*m_cachedCollections)[type - FirstNodeCollectionType];
5960
}
61+
6062
void removeCachedHTMLCollection(HTMLCollection* collection, CollectionType type)
6163
{
6264
ASSERT(m_cachedCollections);
6365
ASSERT_UNUSED(collection, (*m_cachedCollections)[type - FirstNodeCollectionType] == collection);
6466
(*m_cachedCollections)[type - FirstNodeCollectionType] = 0;
6567
}
6668

69+
void clearHTMLCollectionCaches()
70+
{
71+
if (!m_cachedCollections)
72+
return;
73+
74+
for (unsigned i = 0; i < (*m_cachedCollections).size(); i++) {
75+
if ((*m_cachedCollections)[i])
76+
(*m_cachedCollections)[i]->invalidateCache();
77+
}
78+
}
79+
80+
void adoptTreeScope(Document* oldDocument, Document* newDocument)
81+
{
82+
if (!m_cachedCollections)
83+
return;
84+
85+
for (unsigned i = 0; i < (*m_cachedCollections).size(); i++) {
86+
HTMLCollection* collection = (*m_cachedCollections)[i];
87+
if (!collection)
88+
continue;
89+
collection->invalidateCache();
90+
if (oldDocument != newDocument) {
91+
oldDocument->unregisterNodeListCache(collection);
92+
newDocument->registerNodeListCache(collection);
93+
}
94+
}
95+
}
96+
6797
typedef FixedArray<HTMLCollection*, NumNodeCollectionTypes> CachedHTMLCollectionArray;
6898
OwnPtr<CachedHTMLCollectionArray> m_cachedCollections;
6999

0 commit comments

Comments
 (0)