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

Side by Side Diff: Source/core/dom/PresentationAttributeStyle.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/dom/Node.cpp ('k') | Source/core/editing/MarkupAccumulator.cpp » ('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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google 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 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 116 }
117 117
118 static void makePresentationAttributeCacheKey(Element& element, PresentationAttr ibuteCacheKey& result) 118 static void makePresentationAttributeCacheKey(Element& element, PresentationAttr ibuteCacheKey& result)
119 { 119 {
120 // FIXME: Enable for SVG. 120 // FIXME: Enable for SVG.
121 if (!element.isHTMLElement()) 121 if (!element.isHTMLElement())
122 return; 122 return;
123 // Interpretation of the size attributes on <input> depends on the type attr ibute. 123 // Interpretation of the size attributes on <input> depends on the type attr ibute.
124 if (isHTMLInputElement(element)) 124 if (isHTMLInputElement(element))
125 return; 125 return;
126 unsigned size = element.attributeCount(); 126 AttributeIteratorAccessor attributes = element.attributesIterator();
127 for (unsigned i = 0; i < size; ++i) { 127 AttributeConstIterator end = attributes.end();
128 const Attribute& attribute = element.attributeItem(i); 128 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
129 if (!element.isPresentationAttribute(attribute.name())) 129 if (!element.isPresentationAttribute(it->name()))
130 continue; 130 continue;
131 if (!attribute.namespaceURI().isNull()) 131 if (!it->namespaceURI().isNull())
132 return; 132 return;
133 // FIXME: Background URL may depend on the base URL and can't be shared. Disallow caching. 133 // FIXME: Background URL may depend on the base URL and can't be shared. Disallow caching.
134 if (attribute.name() == backgroundAttr) 134 if (it->name() == backgroundAttr)
135 return; 135 return;
136 result.attributesAndValues.append(std::make_pair(attribute.localName().i mpl(), attribute.value())); 136 result.attributesAndValues.append(std::make_pair(it->localName().impl(), it->value()));
137 } 137 }
138 if (result.attributesAndValues.isEmpty()) 138 if (result.attributesAndValues.isEmpty())
139 return; 139 return;
140 // Attribute order doesn't matter. Sort for easy equality comparison. 140 // Attribute order doesn't matter. Sort for easy equality comparison.
141 std::sort(result.attributesAndValues.begin(), result.attributesAndValues.end (), attributeNameSort); 141 std::sort(result.attributesAndValues.begin(), result.attributesAndValues.end (), attributeNameSort);
142 // The cache key is non-null when the tagName is set. 142 // The cache key is non-null when the tagName is set.
143 result.tagName = element.localName().impl(); 143 result.tagName = element.localName().impl();
144 } 144 }
145 145
146 static unsigned computePresentationAttributeCacheHash(const PresentationAttribut eCacheKey& key) 146 static unsigned computePresentationAttributeCacheHash(const PresentationAttribut eCacheKey& key)
(...skipping 24 matching lines...) Expand all
171 } else { 171 } else {
172 cacheValue = 0; 172 cacheValue = 0;
173 } 173 }
174 174
175 RefPtr<StylePropertySet> style; 175 RefPtr<StylePropertySet> style;
176 if (cacheHash && cacheValue->value) { 176 if (cacheHash && cacheValue->value) {
177 style = cacheValue->value->value; 177 style = cacheValue->value->value;
178 cacheCleaner.didHitPresentationAttributeCache(); 178 cacheCleaner.didHitPresentationAttributeCache();
179 } else { 179 } else {
180 style = MutableStylePropertySet::create(element.isSVGElement() ? SVGAttr ibuteMode : HTMLAttributeMode); 180 style = MutableStylePropertySet::create(element.isSVGElement() ? SVGAttr ibuteMode : HTMLAttributeMode);
181 unsigned size = element.attributeCount(); 181 AttributeIteratorAccessor attributes = element.attributesIterator();
182 for (unsigned i = 0; i < size; ++i) { 182 AttributeConstIterator end = attributes.end();
183 const Attribute& attribute = element.attributeItem(i); 183 for (AttributeConstIterator it = attributes.begin(); it != end; ++it)
184 element.collectStyleForPresentationAttribute(attribute.name(), attri bute.value(), toMutableStylePropertySet(style)); 184 element.collectStyleForPresentationAttribute(it->name(), it->value() , toMutableStylePropertySet(style));
185 }
186 } 185 }
187 186
188 if (!cacheHash || cacheValue->value) 187 if (!cacheHash || cacheValue->value)
189 return style.release(); 188 return style.release();
190 189
191 OwnPtr<PresentationAttributeCacheEntry> newEntry = adoptPtr(new Presentation AttributeCacheEntry); 190 OwnPtr<PresentationAttributeCacheEntry> newEntry = adoptPtr(new Presentation AttributeCacheEntry);
192 newEntry->key = cacheKey; 191 newEntry->key = cacheKey;
193 newEntry->value = style; 192 newEntry->value = style;
194 193
195 static const unsigned presentationAttributeCacheMaximumSize = 4096; 194 static const unsigned presentationAttributeCacheMaximumSize = 4096;
196 if (presentationAttributeCache().size() > presentationAttributeCacheMaximumS ize) { 195 if (presentationAttributeCache().size() > presentationAttributeCacheMaximumS ize) {
197 // FIXME: Discarding the entire cache when it gets too big is probably b ad 196 // FIXME: Discarding the entire cache when it gets too big is probably b ad
198 // since it creates a perf "cliff". Perhaps we should use an LRU? 197 // since it creates a perf "cliff". Perhaps we should use an LRU?
199 presentationAttributeCache().clear(); 198 presentationAttributeCache().clear();
200 presentationAttributeCache().set(cacheHash, newEntry.release()); 199 presentationAttributeCache().set(cacheHash, newEntry.release());
201 } else { 200 } else {
202 cacheValue->value = newEntry.release(); 201 cacheValue->value = newEntry.release();
203 } 202 }
204 203
205 return style.release(); 204 return style.release();
206 } 205 }
207 206
208 } // namespace WebCore 207 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Node.cpp ('k') | Source/core/editing/MarkupAccumulator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698