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

Side by Side Diff: Source/core/html/HTMLCollection.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.h ('k') | Source/core/html/HTMLFormControlsCollection.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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 void HTMLCollection::namedPropertyEnumerator(Vector<String>& names, ExceptionSta te&) 435 void HTMLCollection::namedPropertyEnumerator(Vector<String>& names, ExceptionSta te&)
436 { 436 {
437 supportedPropertyNames(names); 437 supportedPropertyNames(names);
438 } 438 }
439 439
440 void HTMLCollection::updateIdNameCache() const 440 void HTMLCollection::updateIdNameCache() const
441 { 441 {
442 if (hasValidIdNameCache()) 442 if (hasValidIdNameCache())
443 return; 443 return;
444 444
445 NamedItemCache& cache = createNamedItemCache(); 445 OwnPtr<NamedItemCache> cache = NamedItemCache::create();
446 for (Element* element = traverseToFirstElement(); element; element = travers eNextElement(*element)) { 446 for (Element* element = traverseToFirstElement(); element; element = travers eNextElement(*element)) {
447 const AtomicString& idAttrVal = element->getIdAttribute(); 447 const AtomicString& idAttrVal = element->getIdAttribute();
448 if (!idAttrVal.isEmpty()) 448 if (!idAttrVal.isEmpty())
449 cache.addElementWithId(idAttrVal, element); 449 cache->addElementWithId(idAttrVal, element);
450 if (!element->isHTMLElement()) 450 if (!element->isHTMLElement())
451 continue; 451 continue;
452 const AtomicString& nameAttrVal = element->getNameAttribute(); 452 const AtomicString& nameAttrVal = element->getNameAttribute();
453 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && (type() != Doc All || nameShouldBeVisibleInDocumentAll(toHTMLElement(*element)))) 453 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && (type() != Doc All || nameShouldBeVisibleInDocumentAll(toHTMLElement(*element))))
454 cache.addElementWithName(nameAttrVal, element); 454 cache->addElementWithName(nameAttrVal, element);
455 } 455 }
456 // Set the named item cache last as traversing the tree may cause cache inva lidation.
457 setNamedItemCache(cache.release());
456 } 458 }
457 459
458 void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Element> >& result) const 460 void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Element> >& result) const
459 { 461 {
460 ASSERT(result.isEmpty()); 462 ASSERT(result.isEmpty());
461 if (name.isEmpty()) 463 if (name.isEmpty())
462 return; 464 return;
463 465
464 updateIdNameCache(); 466 updateIdNameCache();
465 467
466 const NamedItemCache& cache = namedItemCache(); 468 const NamedItemCache& cache = namedItemCache();
467 Vector<Element*>* idResults = cache.getElementsById(name); 469 Vector<Element*>* idResults = cache.getElementsById(name);
468 Vector<Element*>* nameResults = cache.getElementsByName(name); 470 Vector<Element*>* nameResults = cache.getElementsByName(name);
469 471
470 for (unsigned i = 0; idResults && i < idResults->size(); ++i) 472 for (unsigned i = 0; idResults && i < idResults->size(); ++i)
471 result.append(idResults->at(i)); 473 result.append(idResults->at(i));
472 474
473 for (unsigned i = 0; nameResults && i < nameResults->size(); ++i) 475 for (unsigned i = 0; nameResults && i < nameResults->size(); ++i)
474 result.append(nameResults->at(i)); 476 result.append(nameResults->at(i));
475 } 477 }
476 478
479 HTMLCollection::NamedItemCache::NamedItemCache()
480 {
481 }
482
477 } // namespace WebCore 483 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/HTMLCollection.h ('k') | Source/core/html/HTMLFormControlsCollection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698