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

Side by Side Diff: Source/core/html/HTMLCollection.h

Issue 280123002: Oilpan: move LiveNodeList collections to the heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Have NodeRareData clear out NodeListsNodeData instead. Created 6 years, 7 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
« no previous file with comments | « Source/core/html/HTMLAllCollection.idl ('k') | Source/core/html/HTMLCollection.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r ights reserved. 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r ights reserved.
5 * Copyright (C) 2014 Samsung Electronics. All rights reserved. 5 * Copyright (C) 2014 Samsung Electronics. 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 15 matching lines...) Expand all
26 26
27 #include "core/dom/LiveNodeListBase.h" 27 #include "core/dom/LiveNodeListBase.h"
28 #include "core/html/CollectionIndexCache.h" 28 #include "core/html/CollectionIndexCache.h"
29 #include "core/html/CollectionType.h" 29 #include "core/html/CollectionType.h"
30 #include "wtf/Forward.h" 30 #include "wtf/Forward.h"
31 #include "wtf/HashMap.h" 31 #include "wtf/HashMap.h"
32 #include "wtf/Vector.h" 32 #include "wtf/Vector.h"
33 33
34 namespace WebCore { 34 namespace WebCore {
35 35
36 class HTMLCollection : public ScriptWrappable, public RefCounted<HTMLCollection> , public LiveNodeListBase { 36 class HTMLCollection : public RefCountedWillBeGarbageCollectedFinalized<HTMLColl ection>, public ScriptWrappable, public LiveNodeListBase {
37 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(HTMLCollection);
37 public: 38 public:
38 enum ItemAfterOverrideType { 39 enum ItemAfterOverrideType {
39 OverridesItemAfter, 40 OverridesItemAfter,
40 DoesNotOverrideItemAfter, 41 DoesNotOverrideItemAfter,
41 }; 42 };
42 43
43 static PassRefPtr<HTMLCollection> create(ContainerNode& base, CollectionType ); 44 static PassRefPtrWillBeRawPtr<HTMLCollection> create(ContainerNode& base, Co llectionType);
44 virtual ~HTMLCollection(); 45 virtual ~HTMLCollection();
45 virtual void invalidateCache(Document* oldDocument = 0) const OVERRIDE; 46 virtual void invalidateCache(Document* oldDocument = 0) const OVERRIDE;
46 void invalidateCacheForAttribute(const QualifiedName*) const; 47 void invalidateCacheForAttribute(const QualifiedName*) const;
47 48
48 // DOM API 49 // DOM API
49 unsigned length() const { return m_collectionIndexCache.nodeCount(*this); } 50 unsigned length() const { return m_collectionIndexCache.nodeCount(*this); }
50 Element* item(unsigned offset) const { return m_collectionIndexCache.nodeAt( *this, offset); } 51 Element* item(unsigned offset) const { return m_collectionIndexCache.nodeAt( *this, offset); }
51 virtual Element* namedItem(const AtomicString& name) const; 52 virtual Element* namedItem(const AtomicString& name) const;
52 bool namedPropertyQuery(const AtomicString&, ExceptionState&); 53 bool namedPropertyQuery(const AtomicString&, ExceptionState&);
53 void namedPropertyEnumerator(Vector<String>& names, ExceptionState&); 54 void namedPropertyEnumerator(Vector<String>& names, ExceptionState&);
54 55
55 // Non-DOM API 56 // Non-DOM API
56 void namedItems(const AtomicString& name, Vector<RefPtr<Element> >&) const; 57 void namedItems(const AtomicString& name, WillBeHeapVector<RefPtrWillBeMembe r<Element> >&) const;
57 bool isEmpty() const { return m_collectionIndexCache.isEmpty(*this); } 58 bool isEmpty() const { return m_collectionIndexCache.isEmpty(*this); }
58 bool hasExactlyOneItem() const { return m_collectionIndexCache.hasExactlyOne Node(*this); } 59 bool hasExactlyOneItem() const { return m_collectionIndexCache.hasExactlyOne Node(*this); }
59 60
60 // CollectionIndexCache API. 61 // CollectionIndexCache API.
61 bool canTraverseBackward() const { return !overridesItemAfter(); } 62 bool canTraverseBackward() const { return !overridesItemAfter(); }
62 Element* traverseToFirstElement() const; 63 Element* traverseToFirstElement() const;
63 Element* traverseToLastElement() const; 64 Element* traverseToLastElement() const;
64 Element* traverseForwardToOffset(unsigned offset, Element& currentElement, u nsigned& currentOffset) const; 65 Element* traverseForwardToOffset(unsigned offset, Element& currentElement, u nsigned& currentOffset) const;
65 Element* traverseBackwardToOffset(unsigned offset, Element& currentElement, unsigned& currentOffset) const; 66 Element* traverseBackwardToOffset(unsigned offset, Element& currentElement, unsigned& currentOffset) const;
66 67
68 virtual void trace(Visitor*);
69
67 protected: 70 protected:
68 HTMLCollection(ContainerNode& base, CollectionType, ItemAfterOverrideType); 71 HTMLCollection(ContainerNode& base, CollectionType, ItemAfterOverrideType);
69 72
70 class NamedItemCache { 73 class NamedItemCache FINAL : public NoBaseWillBeGarbageCollected<NamedItemCa che> {
71 public: 74 public:
72 static PassOwnPtr<NamedItemCache> create() 75 static PassOwnPtrWillBeRawPtr<NamedItemCache> create()
73 { 76 {
74 return adoptPtr(new NamedItemCache); 77 return adoptPtrWillBeNoop(new NamedItemCache);
75 } 78 }
76 79
77 Vector<Element*>* getElementsById(const AtomicString& id) const { return m_idCache.get(id.impl()); } 80 WillBeHeapVector<RawPtrWillBeMember<Element> >* getElementsById(const At omicString& id) const { return m_idCache.get(id.impl()); }
78 Vector<Element*>* getElementsByName(const AtomicString& name) const { re turn m_nameCache.get(name.impl()); } 81 WillBeHeapVector<RawPtrWillBeMember<Element> >* getElementsByName(const AtomicString& name) const { return m_nameCache.get(name.impl()); }
79 void addElementWithId(const AtomicString& id, Element* element) { addEle mentToMap(m_idCache, id, element); } 82 void addElementWithId(const AtomicString& id, Element* element) { addEle mentToMap(m_idCache, id, element); }
80 void addElementWithName(const AtomicString& name, Element* element) { ad dElementToMap(m_nameCache, name, element); } 83 void addElementWithName(const AtomicString& name, Element* element) { ad dElementToMap(m_nameCache, name, element); }
81 84
85 void trace(Visitor* visitor)
86 {
87 visitor->trace(m_idCache);
88 visitor->trace(m_nameCache);
89 }
90
82 private: 91 private:
83 NamedItemCache(); 92 NamedItemCache();
84 typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > StringToElement sMap; 93 typedef WillBeHeapHashMap<StringImpl*, OwnPtrWillBeMember<WillBeHeapVect or<RawPtrWillBeMember<Element> > > > StringToElementsMap;
85 static void addElementToMap(StringToElementsMap& map, const AtomicString & key, Element* element) 94 static void addElementToMap(StringToElementsMap& map, const AtomicString & key, Element* element)
86 { 95 {
87 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).sto redValue->value; 96 OwnPtrWillBeMember<WillBeHeapVector<RawPtrWillBeMember<Element> > >& vector = map.add(key.impl(), nullptr).storedValue->value;
88 if (!vector) 97 if (!vector)
89 vector = adoptPtr(new Vector<Element*>); 98 vector = adoptPtrWillBeNoop(new WillBeHeapVector<RawPtrWillBeMem ber<Element> >);
90 vector->append(element); 99 vector->append(element);
91 } 100 }
92 101
93 StringToElementsMap m_idCache; 102 StringToElementsMap m_idCache;
94 StringToElementsMap m_nameCache; 103 StringToElementsMap m_nameCache;
95 }; 104 };
96 105
97 bool overridesItemAfter() const { return m_overridesItemAfter; } 106 bool overridesItemAfter() const { return m_overridesItemAfter; }
98 virtual Element* virtualItemAfter(Element*) const; 107 virtual Element* virtualItemAfter(Element*) const;
99 bool shouldOnlyIncludeDirectChildren() const { return m_shouldOnlyIncludeDir ectChildren; } 108 bool shouldOnlyIncludeDirectChildren() const { return m_shouldOnlyIncludeDir ectChildren; }
100 virtual void supportedPropertyNames(Vector<String>& names); 109 virtual void supportedPropertyNames(Vector<String>& names);
101 110
102 virtual void updateIdNameCache() const; 111 virtual void updateIdNameCache() const;
103 bool hasValidIdNameCache() const { return m_namedItemCache; } 112 bool hasValidIdNameCache() const { return m_namedItemCache; }
104 113
105 void setNamedItemCache(PassOwnPtr<NamedItemCache> cache) const 114 void setNamedItemCache(PassOwnPtrWillBeRawPtr<NamedItemCache> cache) const
106 { 115 {
107 ASSERT(!m_namedItemCache); 116 ASSERT(!m_namedItemCache);
108 document().incrementNodeListWithIdNameCacheCount(); 117 document().registerNodeListWithIdNameCache(this);
109 m_namedItemCache = cache; 118 m_namedItemCache = cache;
110 } 119 }
111 120
112 NamedItemCache& namedItemCache() const 121 NamedItemCache& namedItemCache() const
113 { 122 {
114 ASSERT(m_namedItemCache); 123 ASSERT(m_namedItemCache);
115 return *m_namedItemCache; 124 return *m_namedItemCache;
116 } 125 }
117 126
118 private: 127 private:
119 Element* traverseNextElement(Element& previous) const; 128 Element* traverseNextElement(Element& previous) const;
120 129
121 void invalidateIdNameCacheMaps(Document* oldDocument = 0) const 130 void invalidateIdNameCacheMaps(Document* oldDocument = 0) const
122 { 131 {
123 if (!hasValidIdNameCache()) 132 if (!hasValidIdNameCache())
124 return; 133 return;
125 134
126 // Make sure we decrement the NodeListWithIdNameCache count from 135 // Make sure we decrement the NodeListWithIdNameCache count from
127 // the old document instead of the new one in the case the collection 136 // the old document instead of the new one in the case the collection
128 // is moved to a new document. 137 // is moved to a new document.
129 unregisterIdNameCacheFromDocument(oldDocument ? *oldDocument : document( )); 138 unregisterIdNameCacheFromDocument(oldDocument ? *oldDocument : document( ));
130 139
131 m_namedItemCache.clear(); 140 m_namedItemCache.clear();
132 } 141 }
133 142
134 void unregisterIdNameCacheFromDocument(Document& document) const 143 void unregisterIdNameCacheFromDocument(Document& document) const
135 { 144 {
136 ASSERT(hasValidIdNameCache()); 145 ASSERT(hasValidIdNameCache());
137 document.decrementNodeListWithIdNameCacheCount(); 146 document.unregisterNodeListWithIdNameCache(this);
138 } 147 }
139 148
140 const unsigned m_overridesItemAfter : 1; 149 const unsigned m_overridesItemAfter : 1;
141 const unsigned m_shouldOnlyIncludeDirectChildren : 1; 150 const unsigned m_shouldOnlyIncludeDirectChildren : 1;
142 mutable OwnPtr<NamedItemCache> m_namedItemCache; 151 mutable OwnPtrWillBeMember<NamedItemCache> m_namedItemCache;
143 mutable CollectionIndexCache<HTMLCollection, Element> m_collectionIndexCache ; 152 mutable CollectionIndexCache<HTMLCollection, Element> m_collectionIndexCache ;
144 }; 153 };
145 154
146 DEFINE_TYPE_CASTS(HTMLCollection, LiveNodeListBase, collection, isHTMLCollection Type(collection->type()), isHTMLCollectionType(collection.type())); 155 DEFINE_TYPE_CASTS(HTMLCollection, LiveNodeListBase, collection, isHTMLCollection Type(collection->type()), isHTMLCollectionType(collection.type()));
147 156
148 inline void HTMLCollection::invalidateCacheForAttribute(const QualifiedName* att rName) const 157 inline void HTMLCollection::invalidateCacheForAttribute(const QualifiedName* att rName) const
149 { 158 {
150 if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType(), * attrName)) 159 if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType(), * attrName))
151 invalidateCache(); 160 invalidateCache();
152 else if (*attrName == HTMLNames::idAttr || *attrName == HTMLNames::nameAttr) 161 else if (*attrName == HTMLNames::idAttr || *attrName == HTMLNames::nameAttr)
153 invalidateIdNameCacheMaps(); 162 invalidateIdNameCacheMaps();
154 } 163 }
155 164
156 } // namespace 165 } // namespace
157 166
158 #endif 167 #endif
OLDNEW
« no previous file with comments | « Source/core/html/HTMLAllCollection.idl ('k') | Source/core/html/HTMLCollection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698