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

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

Issue 298253009: Add iterator object to iterate efficiently over an Element's attributes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 6 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 | « Source/core/css/SelectorChecker.cpp ('k') | Source/core/dom/Element.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) 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2010 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 { 150 {
151 m_element->deref(); 151 m_element->deref();
152 } 152 }
153 #endif 153 #endif
154 154
155 void DatasetDOMStringMap::getNames(Vector<String>& names) 155 void DatasetDOMStringMap::getNames(Vector<String>& names)
156 { 156 {
157 if (!m_element->hasAttributes()) 157 if (!m_element->hasAttributes())
158 return; 158 return;
159 159
160 unsigned length = m_element->attributeCount(); 160 AttributeIteratorAccessor attributes = m_element->attributesIterator();
161 for (unsigned i = 0; i < length; i++) { 161 AttributeConstIterator end = attributes.end();
162 const Attribute& attribute = m_element->attributeItem(i); 162 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
163 if (isValidAttributeName(attribute.localName())) 163 if (isValidAttributeName(it->localName()))
164 names.append(convertAttributeNameToPropertyName(attribute.localName( ))); 164 names.append(convertAttributeNameToPropertyName(it->localName()));
165 } 165 }
166 } 166 }
167 167
168 String DatasetDOMStringMap::item(const String& name) 168 String DatasetDOMStringMap::item(const String& name)
169 { 169 {
170 if (!m_element->hasAttributes()) 170 if (!m_element->hasAttributes())
171 return String(); 171 return String();
172 172
173 unsigned length = m_element->attributeCount(); 173 AttributeIteratorAccessor attributes = m_element->attributesIterator();
174 for (unsigned i = 0; i < length; i++) { 174 AttributeConstIterator end = attributes.end();
175 const Attribute& attribute = m_element->attributeItem(i); 175 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
176 if (propertyNameMatchesAttributeName(name, attribute.localName())) 176 if (propertyNameMatchesAttributeName(name, it->localName()))
177 return attribute.value(); 177 return it->value();
178 } 178 }
179 179
180 return String(); 180 return String();
181 } 181 }
182 182
183 bool DatasetDOMStringMap::contains(const String& name) 183 bool DatasetDOMStringMap::contains(const String& name)
184 { 184 {
185 if (!m_element->hasAttributes()) 185 if (!m_element->hasAttributes())
186 return false; 186 return false;
187 187
188 unsigned length = m_element->attributeCount(); 188 AttributeIteratorAccessor attributes = m_element->attributesIterator();
189 for (unsigned i = 0; i < length; i++) { 189 AttributeConstIterator end = attributes.end();
190 const Attribute& attribute = m_element->attributeItem(i); 190 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
191 if (propertyNameMatchesAttributeName(name, attribute.localName())) 191 if (propertyNameMatchesAttributeName(name, it->localName()))
192 return true; 192 return true;
193 } 193 }
194
195 return false; 194 return false;
196 } 195 }
197 196
198 void DatasetDOMStringMap::setItem(const String& name, const String& value, Excep tionState& exceptionState) 197 void DatasetDOMStringMap::setItem(const String& name, const String& value, Excep tionState& exceptionState)
199 { 198 {
200 if (!isValidPropertyName(name)) { 199 if (!isValidPropertyName(name)) {
201 exceptionState.throwDOMException(SyntaxError, "'" + name + "' is not a v alid property name."); 200 exceptionState.throwDOMException(SyntaxError, "'" + name + "' is not a v alid property name.");
202 return; 201 return;
203 } 202 }
204 203
(...skipping 12 matching lines...) Expand all
217 return false; 216 return false;
218 } 217 }
219 218
220 void DatasetDOMStringMap::trace(Visitor* visitor) 219 void DatasetDOMStringMap::trace(Visitor* visitor)
221 { 220 {
222 visitor->trace(m_element); 221 visitor->trace(m_element);
223 DOMStringMap::trace(visitor); 222 DOMStringMap::trace(visitor);
224 } 223 }
225 224
226 } // namespace WebCore 225 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/SelectorChecker.cpp ('k') | Source/core/dom/Element.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698