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

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

Issue 138653004: Bring back fast paths for HTMLTagCollection / ClassCollection's access (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 10 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 | « no previous file | 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, 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 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 case ChildNodeListType: 262 case ChildNodeListType:
263 case NameNodeListType: 263 case NameNodeListType:
264 case RadioNodeListType: 264 case RadioNodeListType:
265 case RadioImgNodeListType: 265 case RadioImgNodeListType:
266 case LabelsNodeListType: 266 case LabelsNodeListType:
267 ASSERT_NOT_REACHED(); 267 ASSERT_NOT_REACHED();
268 } 268 }
269 return false; 269 return false;
270 } 270 }
271 271
272 template <> inline bool isMatchingElement(const ClassCollection& collection, con st Element& element)
273 {
274 return collection.elementMatches(element);
275 }
276
277 template <> inline bool isMatchingElement(const HTMLTagCollection& collection, c onst Element& element)
278 {
279 return collection.elementMatches(element);
280 }
281
272 template <> inline bool isMatchingElement(const LiveNodeList& nodeList, const El ement& element) 282 template <> inline bool isMatchingElement(const LiveNodeList& nodeList, const El ement& element)
273 { 283 {
274 return nodeList.nodeMatches(element); 284 return nodeList.nodeMatches(element);
275 } 285 }
276 286
277 static Node* previousNode(const Node& base, const Node& previous, bool onlyInclu deDirectChildren) 287 static Node* previousNode(const Node& base, const Node& previous, bool onlyInclu deDirectChildren)
278 { 288 {
279 return onlyIncludeDirectChildren ? previous.previousSibling() : NodeTraversa l::previous(previous, &base); 289 return onlyIncludeDirectChildren ? previous.previousSibling() : NodeTraversa l::previous(previous, &base);
280 } 290 }
281 291
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 { 445 {
436 Element* next = &current; 446 Element* next = &current;
437 do { 447 do {
438 next = ElementTraversal::nextSkippingChildren(*next, &root); 448 next = ElementTraversal::nextSkippingChildren(*next, &root);
439 } while (next && !isMatchingElement(nodeList, *next)); 449 } while (next && !isMatchingElement(nodeList, *next));
440 return next; 450 return next;
441 } 451 }
442 452
443 Element* HTMLCollection::traverseToFirstElement(const ContainerNode& root) const 453 Element* HTMLCollection::traverseToFirstElement(const ContainerNode& root) const
444 { 454 {
445 if (overridesItemAfter()) 455 switch (type()) {
arv (Not doing code reviews) 2014/02/04 15:12:36 Would it make sense to use virtual dispatch instea
Inactive 2014/02/04 15:30:15 As this is hot code, I think we should avoid virtu
446 return virtualItemAfter(0); 456 case HTMLTagCollectionType:
447 if (shouldOnlyIncludeDirectChildren()) 457 return firstMatchingElement(static_cast<const HTMLTagCollection&>(*this) , root);
448 return firstMatchingChildElement(*this, root); 458 case ClassCollectionType:
449 return firstMatchingElement(*this, root); 459 return firstMatchingElement(static_cast<const ClassCollection&>(*this), root);
460 default:
461 if (overridesItemAfter())
462 return virtualItemAfter(0);
463 if (shouldOnlyIncludeDirectChildren())
464 return firstMatchingChildElement(*this, root);
465 return firstMatchingElement(*this, root);
466 }
450 } 467 }
451 468
452 inline Element* HTMLCollection::traverseNextElement(Element& previous, const Con tainerNode& root) const 469 inline Element* HTMLCollection::traverseNextElement(Element& previous, const Con tainerNode& root) const
453 { 470 {
454 if (overridesItemAfter()) 471 if (overridesItemAfter())
455 return virtualItemAfter(&previous); 472 return virtualItemAfter(&previous);
456 if (shouldOnlyIncludeDirectChildren()) 473 if (shouldOnlyIncludeDirectChildren())
457 return nextMatchingChildElement(*this, previous, root); 474 return nextMatchingChildElement(*this, previous, root);
458 return nextMatchingElement(*this, previous, root); 475 return nextMatchingElement(*this, previous, root);
459 } 476 }
460 477
461 Element* HTMLCollection::traverseForwardToOffset(unsigned offset, Node& currentE lement, unsigned& currentOffset, const ContainerNode& root) const 478 Element* HTMLCollection::traverseForwardToOffset(unsigned offset, Node& currentE lement, unsigned& currentOffset, const ContainerNode& root) const
462 { 479 {
463 ASSERT(currentOffset < offset); 480 ASSERT(currentOffset < offset);
464 if (overridesItemAfter()) { 481 switch (type()) {
465 Element* next = &toElement(currentElement); 482 case HTMLTagCollectionType:
466 while ((next = virtualItemAfter(next))) { 483 return traverseMatchingElementsForwardToOffset(static_cast<const HTMLTag Collection&>(*this), offset, toElement(currentElement), currentOffset, root);
467 if (++currentOffset == offset) 484 case ClassCollectionType:
468 return next; 485 return traverseMatchingElementsForwardToOffset(static_cast<const ClassCo llection&>(*this), offset, toElement(currentElement), currentOffset, root);
486 default:
487 if (overridesItemAfter()) {
488 Element* next = &toElement(currentElement);
489 while ((next = virtualItemAfter(next))) {
490 if (++currentOffset == offset)
491 return next;
492 }
493 return 0;
469 } 494 }
470 return 0; 495 if (shouldOnlyIncludeDirectChildren()) {
496 Element* next = &toElement(currentElement);
497 while ((next = nextMatchingChildElement(*this, *next, root))) {
498 if (++currentOffset == offset)
499 return next;
500 }
501 return 0;
502 }
503 return traverseMatchingElementsForwardToOffset(*this, offset, toElement( currentElement), currentOffset, root);
471 } 504 }
472 if (shouldOnlyIncludeDirectChildren()) {
473 Element* next = &toElement(currentElement);
474 while ((next = nextMatchingChildElement(*this, *next, root))) {
475 if (++currentOffset == offset)
476 return next;
477 }
478 return 0;
479 }
480 return traverseMatchingElementsForwardToOffset(*this, offset, toElement(curr entElement), currentOffset, root);
481 } 505 }
482 506
483 Element* HTMLCollection::namedItem(const AtomicString& name) const 507 Element* HTMLCollection::namedItem(const AtomicString& name) const
484 { 508 {
485 // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/namedit em.asp 509 // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/namedit em.asp
486 // This method first searches for an object with a matching id 510 // This method first searches for an object with a matching id
487 // attribute. If a match is not found, the method then searches for an 511 // attribute. If a match is not found, the method then searches for an
488 // object with a matching name attribute, but only on those elements 512 // object with a matching name attribute, but only on those elements
489 // that are allowed a name attribute. 513 // that are allowed a name attribute.
490 514
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 574
551 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element* element) 575 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element* element)
552 { 576 {
553 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).iterator->v alue; 577 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).iterator->v alue;
554 if (!vector) 578 if (!vector)
555 vector = adoptPtr(new Vector<Element*>); 579 vector = adoptPtr(new Vector<Element*>);
556 vector->append(element); 580 vector->append(element);
557 } 581 }
558 582
559 } // namespace WebCore 583 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698