Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: Source/core/dom/LiveNodeList.h

Issue 159503003: Do not cause unnecessary node lists invalidation on id/name attribute change (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 document().registerNodeList(this); 59 document().registerNodeList(this);
60 } 60 }
61 61
62 virtual ~LiveNodeListBase() 62 virtual ~LiveNodeListBase()
63 { 63 {
64 document().unregisterNodeList(this); 64 document().unregisterNodeList(this);
65 } 65 }
66 66
67 ContainerNode& rootNode() const; 67 ContainerNode& rootNode() const;
68 68
69 void didMoveToDocument(Document& oldDocument, Document& newDocument);
69 ALWAYS_INLINE bool hasIdNameCache() const { return !isLiveNodeListType(type( )); } 70 ALWAYS_INLINE bool hasIdNameCache() const { return !isLiveNodeListType(type( )); }
70 ALWAYS_INLINE bool isRootedAtDocument() const { return m_rootType == NodeLis tIsRootedAtDocument || m_rootType == NodeListIsRootedAtDocumentIfOwnerHasItemref Attr; } 71 ALWAYS_INLINE bool isRootedAtDocument() const { return m_rootType == NodeLis tIsRootedAtDocument || m_rootType == NodeListIsRootedAtDocumentIfOwnerHasItemref Attr; }
71 ALWAYS_INLINE NodeListInvalidationType invalidationType() const { return sta tic_cast<NodeListInvalidationType>(m_invalidationType); } 72 ALWAYS_INLINE NodeListInvalidationType invalidationType() const { return sta tic_cast<NodeListInvalidationType>(m_invalidationType); }
72 ALWAYS_INLINE CollectionType type() const { return static_cast<CollectionTyp e>(m_collectionType); } 73 ALWAYS_INLINE CollectionType type() const { return static_cast<CollectionTyp e>(m_collectionType); }
73 ContainerNode* ownerNode() const { return m_ownerNode.get(); } 74 ContainerNode* ownerNode() const { return m_ownerNode.get(); }
74 ALWAYS_INLINE void invalidateCache(const QualifiedName* attrName) const 75 ALWAYS_INLINE void invalidateCache(const QualifiedName* attrName) const
75 { 76 {
76 if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType( ), *attrName)) 77 if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType( ), *attrName))
77 invalidateCache(); 78 invalidateCache();
78 else if (hasIdNameCache() && (*attrName == HTMLNames::idAttr || *attrNam e == HTMLNames::nameAttr)) 79 else if (hasIdNameCache() && (*attrName == HTMLNames::idAttr || *attrNam e == HTMLNames::nameAttr))
79 invalidateIdNameCacheMaps(); 80 invalidateIdNameCacheMaps();
80 } 81 }
81 virtual void invalidateCache() const = 0; 82 virtual void invalidateCache(Document* oldDocument = 0) const = 0;
82 83
83 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType, const QualifiedName&); 84 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType, const QualifiedName&);
84 85
85 protected: 86 protected:
86 Document& document() const { return m_ownerNode->document(); } 87 Document& document() const { return m_ownerNode->document(); }
87 88
88 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis tRootType>(m_rootType); } 89 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis tRootType>(m_rootType); }
89 90
90 template <typename Collection> 91 template <typename Collection>
91 static Element* iterateForPreviousNode(const Collection&, Node* current); 92 static Element* iterateForPreviousNode(const Collection&, Node* current);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 : LiveNodeListBase(ownerNode.get(), rootType, invalidationType, 132 : LiveNodeListBase(ownerNode.get(), rootType, invalidationType,
132 collectionType) 133 collectionType)
133 { } 134 { }
134 135
135 virtual unsigned length() const OVERRIDE FINAL { return m_collectionIndexCac he.nodeCount(*this); } 136 virtual unsigned length() const OVERRIDE FINAL { return m_collectionIndexCac he.nodeCount(*this); }
136 virtual Node* item(unsigned offset) const OVERRIDE FINAL { return m_collecti onIndexCache.nodeAt(*this, offset); } 137 virtual Node* item(unsigned offset) const OVERRIDE FINAL { return m_collecti onIndexCache.nodeAt(*this, offset); }
137 virtual bool nodeMatches(const Element&) const = 0; 138 virtual bool nodeMatches(const Element&) const = 0;
138 // Avoid ambiguity since both NodeList and LiveNodeListBase have an ownerNod e() method. 139 // Avoid ambiguity since both NodeList and LiveNodeListBase have an ownerNod e() method.
139 using LiveNodeListBase::ownerNode; 140 using LiveNodeListBase::ownerNode;
140 141
141 virtual void invalidateCache() const OVERRIDE FINAL; 142 virtual void invalidateCache(Document* oldDocument) const OVERRIDE FINAL;
142 bool shouldOnlyIncludeDirectChildren() const { return false; } 143 bool shouldOnlyIncludeDirectChildren() const { return false; }
143 144
144 // Collection IndexCache API. 145 // Collection IndexCache API.
145 bool canTraverseBackward() const { return true; } 146 bool canTraverseBackward() const { return true; }
146 Element* itemBefore(const Element* previousItem) const; 147 Element* itemBefore(const Element* previousItem) const;
147 Element* traverseToFirstElement(const ContainerNode& root) const; 148 Element* traverseToFirstElement(const ContainerNode& root) const;
148 Element* traverseForwardToOffset(unsigned offset, Element& currentNode, unsi gned& currentOffset, const ContainerNode& root) const; 149 Element* traverseForwardToOffset(unsigned offset, Element& currentNode, unsi gned& currentOffset, const ContainerNode& root) const;
149 150
150 private: 151 private:
151 virtual bool isLiveNodeList() const OVERRIDE FINAL { return true; } 152 virtual bool isLiveNodeList() const OVERRIDE FINAL { return true; }
152 153
153 mutable CollectionIndexCache<LiveNodeList, Element> m_collectionIndexCache; 154 mutable CollectionIndexCache<LiveNodeList, Element> m_collectionIndexCache;
154 }; 155 };
155 156
156 } // namespace WebCore 157 } // namespace WebCore
157 158
158 #endif // LiveNodeList_h 159 #endif // LiveNodeList_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698