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

Side by Side Diff: Source/core/html/HTMLFormControlsCollection.cpp

Issue 225023034: Make sure named item cache is always valid HTMLCollection::updateIdNameCache() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Move constructor to cpp 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
« no previous file with comments | « Source/core/html/HTMLCollection.cpp ('k') | no next file » | 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, 2010, 2011, 2012 Apple Inc. All r ights reserved. 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010, 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 return item; 146 return item;
147 147
148 return firstNamedItem(formControlElements(), imagesElements, nameAttr, name) ; 148 return firstNamedItem(formControlElements(), imagesElements, nameAttr, name) ;
149 } 149 }
150 150
151 void HTMLFormControlsCollection::updateIdNameCache() const 151 void HTMLFormControlsCollection::updateIdNameCache() const
152 { 152 {
153 if (hasValidIdNameCache()) 153 if (hasValidIdNameCache())
154 return; 154 return;
155 155
156 NamedItemCache& cache = createNamedItemCache(); 156 OwnPtr<NamedItemCache> cache = NamedItemCache::create();
157 HashSet<StringImpl*> foundInputElements; 157 HashSet<StringImpl*> foundInputElements;
158 158
159 const Vector<FormAssociatedElement*>& elementsArray = formControlElements(); 159 const Vector<FormAssociatedElement*>& elementsArray = formControlElements();
160 160
161 for (unsigned i = 0; i < elementsArray.size(); ++i) { 161 for (unsigned i = 0; i < elementsArray.size(); ++i) {
162 FormAssociatedElement* associatedElement = elementsArray[i]; 162 FormAssociatedElement* associatedElement = elementsArray[i];
163 if (associatedElement->isEnumeratable()) { 163 if (associatedElement->isEnumeratable()) {
164 HTMLElement* element = toHTMLElement(associatedElement); 164 HTMLElement* element = toHTMLElement(associatedElement);
165 const AtomicString& idAttrVal = element->getIdAttribute(); 165 const AtomicString& idAttrVal = element->getIdAttribute();
166 const AtomicString& nameAttrVal = element->getNameAttribute(); 166 const AtomicString& nameAttrVal = element->getNameAttribute();
167 if (!idAttrVal.isEmpty()) { 167 if (!idAttrVal.isEmpty()) {
168 cache.addElementWithId(idAttrVal, element); 168 cache->addElementWithId(idAttrVal, element);
169 foundInputElements.add(idAttrVal.impl()); 169 foundInputElements.add(idAttrVal.impl());
170 } 170 }
171 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) { 171 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) {
172 cache.addElementWithName(nameAttrVal, element); 172 cache->addElementWithName(nameAttrVal, element);
173 foundInputElements.add(nameAttrVal.impl()); 173 foundInputElements.add(nameAttrVal.impl());
174 } 174 }
175 } 175 }
176 } 176 }
177 177
178 if (isHTMLFormElement(ownerNode())) { 178 if (isHTMLFormElement(ownerNode())) {
179 const Vector<HTMLImageElement*>& imageElementsArray = formImageElements( ); 179 const Vector<HTMLImageElement*>& imageElementsArray = formImageElements( );
180 for (unsigned i = 0; i < imageElementsArray.size(); ++i) { 180 for (unsigned i = 0; i < imageElementsArray.size(); ++i) {
181 HTMLImageElement* element = imageElementsArray[i]; 181 HTMLImageElement* element = imageElementsArray[i];
182 const AtomicString& idAttrVal = element->getIdAttribute(); 182 const AtomicString& idAttrVal = element->getIdAttribute();
183 const AtomicString& nameAttrVal = element->getNameAttribute(); 183 const AtomicString& nameAttrVal = element->getNameAttribute();
184 if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.i mpl())) 184 if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.i mpl()))
185 cache.addElementWithId(idAttrVal, element); 185 cache->addElementWithId(idAttrVal, element);
186 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && !foundInpu tElements.contains(nameAttrVal.impl())) 186 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && !foundInpu tElements.contains(nameAttrVal.impl()))
187 cache.addElementWithName(nameAttrVal, element); 187 cache->addElementWithName(nameAttrVal, element);
188 } 188 }
189 } 189 }
190
191 // Set the named item cache last as traversing the tree may cause cache inva lidation.
192 setNamedItemCache(cache.release());
190 } 193 }
191 194
192 void HTMLFormControlsCollection::namedGetter(const AtomicString& name, bool& rad ioNodeListEnabled, RefPtr<RadioNodeList>& radioNodeList, bool& elementEnabled, R efPtr<Element>& element) 195 void HTMLFormControlsCollection::namedGetter(const AtomicString& name, bool& rad ioNodeListEnabled, RefPtr<RadioNodeList>& radioNodeList, bool& elementEnabled, R efPtr<Element>& element)
193 { 196 {
194 Vector<RefPtr<Element> > namedItems; 197 Vector<RefPtr<Element> > namedItems;
195 this->namedItems(name, namedItems); 198 this->namedItems(name, namedItems);
196 199
197 if (namedItems.isEmpty()) 200 if (namedItems.isEmpty())
198 return; 201 return;
199 202
(...skipping 28 matching lines...) Expand all
228 const AtomicString& nameAttribute = element->getNameAttribute(); 231 const AtomicString& nameAttribute = element->getNameAttribute();
229 if (!nameAttribute.isEmpty()) { 232 if (!nameAttribute.isEmpty()) {
230 HashSet<AtomicString>::AddResult addResult = existingNames.add(nameA ttribute); 233 HashSet<AtomicString>::AddResult addResult = existingNames.add(nameA ttribute);
231 if (addResult.isNewEntry) 234 if (addResult.isNewEntry)
232 names.append(nameAttribute); 235 names.append(nameAttribute);
233 } 236 }
234 } 237 }
235 } 238 }
236 239
237 } 240 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLCollection.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698