Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 | |
| 146 Map::iterator it = m_map.find(key); | |
| 147 if (it == m_map.end()) { | |
| 148 DEFINE_STATIC_LOCAL(Vector<Element*>, emptyVector, ()); | |
|
esprehn
2013/12/18 00:16:50
nit: This should be at the top of the function.
Inactive
2013/12/18 15:25:56
Done.
| |
| 149 return emptyVector; | |
| 150 } | |
| 151 | |
| 152 MapEntry& entry = it->value; | |
| 153 ASSERT(entry.count); | |
| 154 | |
| 155 if (entry.orderedList.isEmpty()) { | |
| 156 entry.orderedList.reserveCapacity(entry.count); | |
| 157 for (Element* element = entry.element ? entry.element : ElementTraversal ::firstWithin(*scope->rootNode()); entry.orderedList.size() < entry.count; eleme nt = ElementTraversal::next(*element)) { | |
| 158 ASSERT(element); | |
| 159 if (!keyMatchesId(key, element)) | |
| 160 continue; | |
| 161 entry.orderedList.uncheckedAppend(element); | |
| 162 } | |
| 163 if (!entry.element) | |
| 164 entry.element = entry.orderedList.first(); | |
| 165 } | |
| 166 | |
| 167 return entry.orderedList; | |
| 168 } | |
| 169 | |
| 137 Element* DocumentOrderedMap::getElementByMapName(StringImpl* key, const TreeScop e* scope) const | 170 Element* DocumentOrderedMap::getElementByMapName(StringImpl* key, const TreeScop e* scope) const |
| 138 { | 171 { |
| 139 return get<keyMatchesMapName>(key, scope); | 172 return get<keyMatchesMapName>(key, scope); |
| 140 } | 173 } |
| 141 | 174 |
| 142 Element* DocumentOrderedMap::getElementByLowercasedMapName(StringImpl* key, cons t TreeScope* scope) const | 175 Element* DocumentOrderedMap::getElementByLowercasedMapName(StringImpl* key, cons t TreeScope* scope) const |
| 143 { | 176 { |
| 144 return get<keyMatchesLowercasedMapName>(key, scope); | 177 return get<keyMatchesLowercasedMapName>(key, scope); |
| 145 } | 178 } |
| 146 | 179 |
| 147 Element* DocumentOrderedMap::getElementByLabelForAttribute(StringImpl* key, cons t TreeScope* scope) const | 180 Element* DocumentOrderedMap::getElementByLabelForAttribute(StringImpl* key, cons t TreeScope* scope) const |
| 148 { | 181 { |
| 149 return get<keyMatchesLabelForAttribute>(key, scope); | 182 return get<keyMatchesLabelForAttribute>(key, scope); |
| 150 } | 183 } |
| 151 | 184 |
| 152 } // namespace WebCore | 185 } // namespace WebCore |
| OLD | NEW |