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

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

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/HTMLCollection.h ('k') | Source/core/html/HTMLCollection.idl » ('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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 159 }
160 160
161 HTMLCollection::HTMLCollection(ContainerNode& ownerNode, CollectionType type, It emAfterOverrideType itemAfterOverrideType) 161 HTMLCollection::HTMLCollection(ContainerNode& ownerNode, CollectionType type, It emAfterOverrideType itemAfterOverrideType)
162 : LiveNodeListBase(ownerNode, rootTypeFromCollectionType(type), invalidation TypeExcludingIdAndNameAttributes(type), type) 162 : LiveNodeListBase(ownerNode, rootTypeFromCollectionType(type), invalidation TypeExcludingIdAndNameAttributes(type), type)
163 , m_overridesItemAfter(itemAfterOverrideType == OverridesItemAfter) 163 , m_overridesItemAfter(itemAfterOverrideType == OverridesItemAfter)
164 , m_shouldOnlyIncludeDirectChildren(shouldTypeOnlyIncludeDirectChildren(type )) 164 , m_shouldOnlyIncludeDirectChildren(shouldTypeOnlyIncludeDirectChildren(type ))
165 { 165 {
166 ScriptWrappable::init(this); 166 ScriptWrappable::init(this);
167 } 167 }
168 168
169 PassRefPtr<HTMLCollection> HTMLCollection::create(ContainerNode& base, Collectio nType type) 169 PassRefPtrWillBeRawPtr<HTMLCollection> HTMLCollection::create(ContainerNode& bas e, CollectionType type)
170 { 170 {
171 return adoptRef(new HTMLCollection(base, type, DoesNotOverrideItemAfter)); 171 return adoptRefWillBeNoop(new HTMLCollection(base, type, DoesNotOverrideItem After));
172 } 172 }
173 173
174 HTMLCollection::~HTMLCollection() 174 HTMLCollection::~HTMLCollection()
175 { 175 {
176 #if !ENABLE(OILPAN)
176 if (hasValidIdNameCache()) 177 if (hasValidIdNameCache())
177 unregisterIdNameCacheFromDocument(document()); 178 unregisterIdNameCacheFromDocument(document());
178 // Named HTMLCollection types remove cache by themselves. 179 // Named HTMLCollection types remove cache by themselves.
179 if (isUnnamedHTMLCollectionType(type())) 180 if (isUnnamedHTMLCollectionType(type()))
180 ownerNode().nodeLists()->removeCache(this, type()); 181 ownerNode().nodeLists()->removeCache(this, type());
182 #endif
181 } 183 }
182 184
183 void HTMLCollection::invalidateCache(Document* oldDocument) const 185 void HTMLCollection::invalidateCache(Document* oldDocument) const
184 { 186 {
185 m_collectionIndexCache.invalidate(); 187 m_collectionIndexCache.invalidate();
186 invalidateIdNameCacheMaps(oldDocument); 188 invalidateIdNameCacheMaps(oldDocument);
187 } 189 }
188 190
189 template <class NodeListType> 191 template <class NodeListType>
190 inline bool isMatchingElement(const NodeListType&, const Element&); 192 inline bool isMatchingElement(const NodeListType&, const Element&);
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 Element* HTMLCollection::namedItem(const AtomicString& name) const 415 Element* HTMLCollection::namedItem(const AtomicString& name) const
414 { 416 {
415 // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/namedit em.asp 417 // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/namedit em.asp
416 // This method first searches for an object with a matching id 418 // This method first searches for an object with a matching id
417 // attribute. If a match is not found, the method then searches for an 419 // attribute. If a match is not found, the method then searches for an
418 // object with a matching name attribute, but only on those elements 420 // object with a matching name attribute, but only on those elements
419 // that are allowed a name attribute. 421 // that are allowed a name attribute.
420 updateIdNameCache(); 422 updateIdNameCache();
421 423
422 const NamedItemCache& cache = namedItemCache(); 424 const NamedItemCache& cache = namedItemCache();
423 Vector<Element*>* idResults = cache.getElementsById(name); 425 WillBeHeapVector<RawPtrWillBeMember<Element> >* idResults = cache.getElement sById(name);
424 if (idResults && !idResults->isEmpty()) 426 if (idResults && !idResults->isEmpty())
425 return idResults->first(); 427 return idResults->first();
426 428
427 Vector<Element*>* nameResults = cache.getElementsByName(name); 429 WillBeHeapVector<RawPtrWillBeMember<Element> >* nameResults = cache.getEleme ntsByName(name);
428 if (nameResults && !nameResults->isEmpty()) 430 if (nameResults && !nameResults->isEmpty())
429 return nameResults->first(); 431 return nameResults->first();
430 432
431 return 0; 433 return 0;
432 } 434 }
433 435
434 bool HTMLCollection::namedPropertyQuery(const AtomicString& name, ExceptionState &) 436 bool HTMLCollection::namedPropertyQuery(const AtomicString& name, ExceptionState &)
435 { 437 {
436 return namedItem(name); 438 return namedItem(name);
437 } 439 }
(...skipping 30 matching lines...) Expand all
468 void HTMLCollection::namedPropertyEnumerator(Vector<String>& names, ExceptionSta te&) 470 void HTMLCollection::namedPropertyEnumerator(Vector<String>& names, ExceptionSta te&)
469 { 471 {
470 supportedPropertyNames(names); 472 supportedPropertyNames(names);
471 } 473 }
472 474
473 void HTMLCollection::updateIdNameCache() const 475 void HTMLCollection::updateIdNameCache() const
474 { 476 {
475 if (hasValidIdNameCache()) 477 if (hasValidIdNameCache())
476 return; 478 return;
477 479
478 OwnPtr<NamedItemCache> cache = NamedItemCache::create(); 480 OwnPtrWillBeRawPtr<NamedItemCache> cache = NamedItemCache::create();
479 for (Element* element = traverseToFirstElement(); element; element = travers eNextElement(*element)) { 481 for (Element* element = traverseToFirstElement(); element; element = travers eNextElement(*element)) {
480 const AtomicString& idAttrVal = element->getIdAttribute(); 482 const AtomicString& idAttrVal = element->getIdAttribute();
481 if (!idAttrVal.isEmpty()) 483 if (!idAttrVal.isEmpty())
482 cache->addElementWithId(idAttrVal, element); 484 cache->addElementWithId(idAttrVal, element);
483 if (!element->isHTMLElement()) 485 if (!element->isHTMLElement())
484 continue; 486 continue;
485 const AtomicString& nameAttrVal = element->getNameAttribute(); 487 const AtomicString& nameAttrVal = element->getNameAttribute();
486 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && (type() != Doc All || nameShouldBeVisibleInDocumentAll(toHTMLElement(*element)))) 488 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && (type() != Doc All || nameShouldBeVisibleInDocumentAll(toHTMLElement(*element))))
487 cache->addElementWithName(nameAttrVal, element); 489 cache->addElementWithName(nameAttrVal, element);
488 } 490 }
489 // Set the named item cache last as traversing the tree may cause cache inva lidation. 491 // Set the named item cache last as traversing the tree may cause cache inva lidation.
490 setNamedItemCache(cache.release()); 492 setNamedItemCache(cache.release());
491 } 493 }
492 494
493 void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Element> >& result) const 495 void HTMLCollection::namedItems(const AtomicString& name, WillBeHeapVector<RefPt rWillBeMember<Element> >& result) const
494 { 496 {
495 ASSERT(result.isEmpty()); 497 ASSERT(result.isEmpty());
496 if (name.isEmpty()) 498 if (name.isEmpty())
497 return; 499 return;
498 500
499 updateIdNameCache(); 501 updateIdNameCache();
500 502
501 const NamedItemCache& cache = namedItemCache(); 503 const NamedItemCache& cache = namedItemCache();
502 Vector<Element*>* idResults = cache.getElementsById(name); 504 WillBeHeapVector<RawPtrWillBeMember<Element> >* idResults = cache.getElement sById(name);
503 Vector<Element*>* nameResults = cache.getElementsByName(name); 505 WillBeHeapVector<RawPtrWillBeMember<Element> >* nameResults = cache.getEleme ntsByName(name);
504 506
505 for (unsigned i = 0; idResults && i < idResults->size(); ++i) 507 for (unsigned i = 0; idResults && i < idResults->size(); ++i)
506 result.append(idResults->at(i)); 508 result.append(idResults->at(i));
507 509
508 for (unsigned i = 0; nameResults && i < nameResults->size(); ++i) 510 for (unsigned i = 0; nameResults && i < nameResults->size(); ++i)
509 result.append(nameResults->at(i)); 511 result.append(nameResults->at(i));
510 } 512 }
511 513
512 HTMLCollection::NamedItemCache::NamedItemCache() 514 HTMLCollection::NamedItemCache::NamedItemCache()
513 { 515 {
514 } 516 }
515 517
518 void HTMLCollection::trace(Visitor* visitor)
519 {
520 visitor->trace(m_namedItemCache);
521 visitor->trace(m_collectionIndexCache);
522 LiveNodeListBase::trace(visitor);
523 }
524
516 } // namespace WebCore 525 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/HTMLCollection.h ('k') | Source/core/html/HTMLCollection.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698