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

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

Issue 225023034: Make sure named item cache is always valid HTMLCollection::updateIdNameCache() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make constructor private Created 6 years, 8 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 * 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 bool canTraverseBackward() const { return !overridesItemAfter(); } 60 bool canTraverseBackward() const { return !overridesItemAfter(); }
61 Element* itemBefore(const Element* previousItem) const; 61 Element* itemBefore(const Element* previousItem) const;
62 Element* traverseToFirstElement() const; 62 Element* traverseToFirstElement() const;
63 Element* traverseForwardToOffset(unsigned offset, Element& currentElement, u nsigned& currentOffset) const; 63 Element* traverseForwardToOffset(unsigned offset, Element& currentElement, u nsigned& currentOffset) const;
64 64
65 protected: 65 protected:
66 HTMLCollection(ContainerNode& base, CollectionType, ItemAfterOverrideType); 66 HTMLCollection(ContainerNode& base, CollectionType, ItemAfterOverrideType);
67 67
68 class NamedItemCache { 68 class NamedItemCache {
69 public: 69 public:
70 static PassOwnPtr<NamedItemCache> create()
71 {
72 return adoptPtr(new NamedItemCache);
73 }
74
70 Vector<Element*>* getElementsById(const AtomicString& id) const { return m_idCache.get(id.impl()); } 75 Vector<Element*>* getElementsById(const AtomicString& id) const { return m_idCache.get(id.impl()); }
71 Vector<Element*>* getElementsByName(const AtomicString& name) const { re turn m_nameCache.get(name.impl()); } 76 Vector<Element*>* getElementsByName(const AtomicString& name) const { re turn m_nameCache.get(name.impl()); }
72 void addElementWithId(const AtomicString& id, Element* element) { addEle mentToMap(m_idCache, id, element); } 77 void addElementWithId(const AtomicString& id, Element* element) { addEle mentToMap(m_idCache, id, element); }
73 void addElementWithName(const AtomicString& name, Element* element) { ad dElementToMap(m_nameCache, name, element); } 78 void addElementWithName(const AtomicString& name, Element* element) { ad dElementToMap(m_nameCache, name, element); }
74 79
75 private: 80 private:
81 NamedItemCache() { }
eseidel 2014/04/08 02:12:55 Best to put all functions in the .cpp file when po
Inactive 2014/04/08 02:21:08 Done.
76 typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > StringToElement sMap; 82 typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > StringToElement sMap;
77 static void addElementToMap(StringToElementsMap& map, const AtomicString & key, Element* element) 83 static void addElementToMap(StringToElementsMap& map, const AtomicString & key, Element* element)
78 { 84 {
79 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).sto redValue->value; 85 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).sto redValue->value;
80 if (!vector) 86 if (!vector)
81 vector = adoptPtr(new Vector<Element*>); 87 vector = adoptPtr(new Vector<Element*>);
82 vector->append(element); 88 vector->append(element);
83 } 89 }
84 90
85 StringToElementsMap m_idCache; 91 StringToElementsMap m_idCache;
86 StringToElementsMap m_nameCache; 92 StringToElementsMap m_nameCache;
87 }; 93 };
88 94
89 bool overridesItemAfter() const { return m_overridesItemAfter; } 95 bool overridesItemAfter() const { return m_overridesItemAfter; }
90 virtual Element* virtualItemAfter(Element*) const; 96 virtual Element* virtualItemAfter(Element*) const;
91 bool shouldOnlyIncludeDirectChildren() const { return m_shouldOnlyIncludeDir ectChildren; } 97 bool shouldOnlyIncludeDirectChildren() const { return m_shouldOnlyIncludeDir ectChildren; }
92 virtual void supportedPropertyNames(Vector<String>& names); 98 virtual void supportedPropertyNames(Vector<String>& names);
93 99
94 virtual void updateIdNameCache() const; 100 virtual void updateIdNameCache() const;
95 bool hasValidIdNameCache() const { return m_namedItemCache; } 101 bool hasValidIdNameCache() const { return m_namedItemCache; }
96 102
97 NamedItemCache& createNamedItemCache() const 103 void setNamedItemCache(PassOwnPtr<NamedItemCache> cache) const
98 { 104 {
99 ASSERT(!m_namedItemCache); 105 ASSERT(!m_namedItemCache);
100 document().incrementNodeListWithIdNameCacheCount(); 106 document().incrementNodeListWithIdNameCacheCount();
101 m_namedItemCache = adoptPtr(new NamedItemCache); 107 m_namedItemCache = cache;
102 return *m_namedItemCache;
103 } 108 }
109
104 NamedItemCache& namedItemCache() const 110 NamedItemCache& namedItemCache() const
105 { 111 {
106 ASSERT(m_namedItemCache); 112 ASSERT(m_namedItemCache);
107 return *m_namedItemCache; 113 return *m_namedItemCache;
108 } 114 }
109 115
110 private: 116 private:
111 Element* traverseNextElement(Element& previous) const; 117 Element* traverseNextElement(Element& previous) const;
112 118
113 void invalidateIdNameCacheMaps(Document* oldDocument = 0) const 119 void invalidateIdNameCacheMaps(Document* oldDocument = 0) const
(...skipping 19 matching lines...) Expand all
133 const unsigned m_shouldOnlyIncludeDirectChildren : 1; 139 const unsigned m_shouldOnlyIncludeDirectChildren : 1;
134 mutable OwnPtr<NamedItemCache> m_namedItemCache; 140 mutable OwnPtr<NamedItemCache> m_namedItemCache;
135 mutable CollectionIndexCache<HTMLCollection, Element> m_collectionIndexCache ; 141 mutable CollectionIndexCache<HTMLCollection, Element> m_collectionIndexCache ;
136 142
137 friend class LiveNodeListBase; 143 friend class LiveNodeListBase;
138 }; 144 };
139 145
140 } // namespace 146 } // namespace
141 147
142 #endif 148 #endif
OLDNEW
« no previous file with comments | « LayoutTests/fast/dom/htmlcollection-selectedOptions-namedItem-crash-expected.txt ('k') | Source/core/html/HTMLCollection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698