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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLAllCollection.cpp

Issue 2765653002: Remove a level of indirection in HTMLCollection. (Closed)
Patch Set: Created 3 years, 9 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 | « no previous file | third_party/WebKit/Source/core/html/HTMLCollection.h » ('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) 2009, 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2009, 2011, 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 29 matching lines...) Expand all
40 HTMLAllCollection::HTMLAllCollection(ContainerNode& node) 40 HTMLAllCollection::HTMLAllCollection(ContainerNode& node)
41 : HTMLCollection(node, DocAll, DoesNotOverrideItemAfter) {} 41 : HTMLCollection(node, DocAll, DoesNotOverrideItemAfter) {}
42 42
43 HTMLAllCollection::~HTMLAllCollection() {} 43 HTMLAllCollection::~HTMLAllCollection() {}
44 44
45 Element* HTMLAllCollection::namedItemWithIndex(const AtomicString& name, 45 Element* HTMLAllCollection::namedItemWithIndex(const AtomicString& name,
46 unsigned index) const { 46 unsigned index) const {
47 updateIdNameCache(); 47 updateIdNameCache();
48 48
49 const NamedItemCache& cache = namedItemCache(); 49 const NamedItemCache& cache = namedItemCache();
50 if (HeapVector<Member<Element>>* elements = cache.getElementsById(name)) { 50 if (const auto* elements = cache.getElementsById(name)) {
51 if (index < elements->size()) 51 if (index < elements->size())
52 return elements->at(index); 52 return elements->at(index);
53 index -= elements->size(); 53 index -= elements->size();
54 } 54 }
55 55
56 if (HeapVector<Member<Element>>* elements = cache.getElementsByName(name)) { 56 if (const auto* elements = cache.getElementsByName(name)) {
57 if (index < elements->size()) 57 if (index < elements->size())
58 return elements->at(index); 58 return elements->at(index);
59 } 59 }
60 60
61 return 0; 61 return nullptr;
62 } 62 }
63 63
64 void HTMLAllCollection::namedGetter(const AtomicString& name, 64 void HTMLAllCollection::namedGetter(const AtomicString& name,
65 NodeListOrElement& returnValue) { 65 NodeListOrElement& returnValue) {
66 HeapVector<Member<Element>> namedItems; 66 HeapVector<Member<Element>> namedItems;
67 this->namedItems(name, namedItems); 67 this->namedItems(name, namedItems);
68 68
69 if (!namedItems.size()) 69 if (!namedItems.size())
70 return; 70 return;
71 71
72 if (namedItems.size() == 1) { 72 if (namedItems.size() == 1) {
73 returnValue.setElement(namedItems.at(0)); 73 returnValue.setElement(namedItems.at(0));
74 return; 74 return;
75 } 75 }
76 76
77 // FIXME: HTML5 specification says this should be a HTMLCollection. 77 // FIXME: HTML5 specification says this should be a HTMLCollection.
78 // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-inte rfaces.html#htmlallcollection 78 // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-inte rfaces.html#htmlallcollection
79 returnValue.setNodeList(StaticElementList::adopt(namedItems)); 79 returnValue.setNodeList(StaticElementList::adopt(namedItems));
80 } 80 }
81 81
82 } // namespace blink 82 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/html/HTMLCollection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698