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

Unified Diff: third_party/WebKit/Source/core/html/HTMLCollection.h

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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/HTMLCollection.h
diff --git a/third_party/WebKit/Source/core/html/HTMLCollection.h b/third_party/WebKit/Source/core/html/HTMLCollection.h
index 474332fd1720964f0572f7ca3fc655889e64c870..f38ec1d4fbaa89d954499aff8beb780538a9181b 100644
--- a/third_party/WebKit/Source/core/html/HTMLCollection.h
+++ b/third_party/WebKit/Source/core/html/HTMLCollection.h
@@ -122,12 +122,19 @@ class CORE_EXPORT HTMLCollection
public:
static NamedItemCache* create() { return new NamedItemCache; }
- HeapVector<Member<Element>>* getElementsById(const AtomicString& id) const {
- return m_idCache.at(id.impl());
+ const HeapVector<Member<Element>>* getElementsById(
+ const AtomicString& id) const {
+ auto it = m_idCache.find(id.impl());
+ if (it == m_idCache.end())
+ return nullptr;
+ return &it->value;
}
- HeapVector<Member<Element>>* getElementsByName(
+ const HeapVector<Member<Element>>* getElementsByName(
const AtomicString& name) const {
- return m_nameCache.at(name.impl());
+ auto it = m_nameCache.find(name.impl());
+ if (it == m_nameCache.end())
+ return nullptr;
+ return &it->value;
}
void addElementWithId(const AtomicString& id, Element* element) {
addElementToMap(m_idCache, id, element);
@@ -143,16 +150,15 @@ class CORE_EXPORT HTMLCollection
private:
NamedItemCache();
- typedef HeapHashMap<StringImpl*, Member<HeapVector<Member<Element>>>>
+ typedef HeapHashMap<StringImpl*, HeapVector<Member<Element>>>
StringToElementsMap;
static void addElementToMap(StringToElementsMap& map,
const AtomicString& key,
Element* element) {
- Member<HeapVector<Member<Element>>>& vector =
- map.insert(key.impl(), nullptr).storedValue->value;
- if (!vector)
- vector = new HeapVector<Member<Element>>;
- vector->push_back(element);
+ HeapVector<Member<Element>>& vector =
+ map.insert(key.impl(), HeapVector<Member<Element>>())
+ .storedValue->value;
+ vector.push_back(element);
}
StringToElementsMap m_idCache;
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLAllCollection.cpp ('k') | third_party/WebKit/Source/core/html/HTMLCollection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698