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

Side by Side Diff: Source/core/dom/DocumentOrderedMap.cpp

Issue 92083002: Add fast path for tag#id selector queries (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Move emptyVector Created 7 years 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/dom/DocumentOrderedMap.h ('k') | Source/core/dom/SelectorQuery.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) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 ASSERT(element); 73 ASSERT(element);
74 74
75 Map::AddResult addResult = m_map.add(key, MapEntry(element)); 75 Map::AddResult addResult = m_map.add(key, MapEntry(element));
76 if (addResult.isNewEntry) 76 if (addResult.isNewEntry)
77 return; 77 return;
78 78
79 MapEntry& entry = addResult.iterator->value; 79 MapEntry& entry = addResult.iterator->value;
80 ASSERT(entry.count); 80 ASSERT(entry.count);
81 entry.element = 0; 81 entry.element = 0;
82 entry.count++; 82 entry.count++;
83 entry.orderedList.clear();
83 } 84 }
84 85
85 void DocumentOrderedMap::remove(StringImpl* key, Element* element) 86 void DocumentOrderedMap::remove(StringImpl* key, Element* element)
86 { 87 {
87 ASSERT(key); 88 ASSERT(key);
88 ASSERT(element); 89 ASSERT(element);
89 90
90 Map::iterator it = m_map.find(key); 91 Map::iterator it = m_map.find(key);
91 if (it == m_map.end()) 92 if (it == m_map.end())
92 return; 93 return;
93 94
94 MapEntry& entry = it->value; 95 MapEntry& entry = it->value;
95 ASSERT(entry.count); 96 ASSERT(entry.count);
96 if (entry.count == 1) { 97 if (entry.count == 1) {
97 ASSERT(!entry.element || entry.element == element); 98 ASSERT(!entry.element || entry.element == element);
98 m_map.remove(it); 99 m_map.remove(it);
99 } else { 100 } else {
100 if (entry.element == element) 101 if (entry.element == element) {
101 entry.element = 0; 102 ASSERT(entry.orderedList.isEmpty() || entry.orderedList.first() == e lement);
103 entry.element = entry.orderedList.size() > 1 ? entry.orderedList[1] : 0;
104 }
102 entry.count--; 105 entry.count--;
106 entry.orderedList.clear();
103 } 107 }
104 } 108 }
105 109
106 template<bool keyMatches(StringImpl*, Element*)> 110 template<bool keyMatches(StringImpl*, Element*)>
107 inline Element* DocumentOrderedMap::get(StringImpl* key, const TreeScope* scope) const 111 inline Element* DocumentOrderedMap::get(StringImpl* key, const TreeScope* scope) const
108 { 112 {
109 ASSERT(key); 113 ASSERT(key);
110 ASSERT(scope); 114 ASSERT(scope);
111 115
112 Map::iterator it = m_map.find(key); 116 Map::iterator it = m_map.find(key);
(...skipping 14 matching lines...) Expand all
127 } 131 }
128 ASSERT_NOT_REACHED(); 132 ASSERT_NOT_REACHED();
129 return 0; 133 return 0;
130 } 134 }
131 135
132 Element* DocumentOrderedMap::getElementById(StringImpl* key, const TreeScope* sc ope) const 136 Element* DocumentOrderedMap::getElementById(StringImpl* key, const TreeScope* sc ope) const
133 { 137 {
134 return get<keyMatchesId>(key, scope); 138 return get<keyMatchesId>(key, scope);
135 } 139 }
136 140
141 const Vector<Element*>& DocumentOrderedMap::getAllElementsById(StringImpl* key, const TreeScope* scope) const
142 {
143 ASSERT(key);
144 ASSERT(scope);
145 DEFINE_STATIC_LOCAL(Vector<Element*>, emptyVector, ());
146
147 Map::iterator it = m_map.find(key);
148 if (it == m_map.end())
149 return emptyVector;
150
151 MapEntry& entry = it->value;
152 ASSERT(entry.count);
153
154 if (entry.orderedList.isEmpty()) {
155 entry.orderedList.reserveCapacity(entry.count);
156 for (Element* element = entry.element ? entry.element : ElementTraversal ::firstWithin(*scope->rootNode()); entry.orderedList.size() < entry.count; eleme nt = ElementTraversal::next(*element)) {
157 ASSERT(element);
158 if (!keyMatchesId(key, element))
159 continue;
160 entry.orderedList.uncheckedAppend(element);
161 }
162 if (!entry.element)
163 entry.element = entry.orderedList.first();
164 }
165
166 return entry.orderedList;
167 }
168
137 Element* DocumentOrderedMap::getElementByMapName(StringImpl* key, const TreeScop e* scope) const 169 Element* DocumentOrderedMap::getElementByMapName(StringImpl* key, const TreeScop e* scope) const
138 { 170 {
139 return get<keyMatchesMapName>(key, scope); 171 return get<keyMatchesMapName>(key, scope);
140 } 172 }
141 173
142 Element* DocumentOrderedMap::getElementByLowercasedMapName(StringImpl* key, cons t TreeScope* scope) const 174 Element* DocumentOrderedMap::getElementByLowercasedMapName(StringImpl* key, cons t TreeScope* scope) const
143 { 175 {
144 return get<keyMatchesLowercasedMapName>(key, scope); 176 return get<keyMatchesLowercasedMapName>(key, scope);
145 } 177 }
146 178
147 Element* DocumentOrderedMap::getElementByLabelForAttribute(StringImpl* key, cons t TreeScope* scope) const 179 Element* DocumentOrderedMap::getElementByLabelForAttribute(StringImpl* key, cons t TreeScope* scope) const
148 { 180 {
149 return get<keyMatchesLabelForAttribute>(key, scope); 181 return get<keyMatchesLabelForAttribute>(key, scope);
150 } 182 }
151 183
152 } // namespace WebCore 184 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/DocumentOrderedMap.h ('k') | Source/core/dom/SelectorQuery.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698