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

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

Issue 138643003: Simpler return value of HashTable::add/HashMap:add and others (Closed)
Patch Set: Daily master update (now with base url?) Created 6 years, 10 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
« no previous file with comments | « Source/core/dom/NodeRareData.h ('k') | Source/core/dom/QualifiedName.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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 { 156 {
157 DEFINE_STATIC_LOCAL(PresentationAttributeCacheCleaner, cacheCleaner, ()); 157 DEFINE_STATIC_LOCAL(PresentationAttributeCacheCleaner, cacheCleaner, ());
158 158
159 ASSERT(element.isStyledElement()); 159 ASSERT(element.isStyledElement());
160 160
161 PresentationAttributeCacheKey cacheKey; 161 PresentationAttributeCacheKey cacheKey;
162 makePresentationAttributeCacheKey(element, cacheKey); 162 makePresentationAttributeCacheKey(element, cacheKey);
163 163
164 unsigned cacheHash = computePresentationAttributeCacheHash(cacheKey); 164 unsigned cacheHash = computePresentationAttributeCacheHash(cacheKey);
165 165
166 PresentationAttributeCache::iterator cacheIterator; 166 PresentationAttributeCache::ValueType* cacheValue;
167 if (cacheHash) { 167 if (cacheHash) {
168 cacheIterator = presentationAttributeCache().add(cacheHash, nullptr).ite rator; 168 cacheValue = presentationAttributeCache().add(cacheHash, nullptr).stored Value;
169 if (cacheIterator->value && cacheIterator->value->key != cacheKey) 169 if (cacheValue->value && cacheValue->value->key != cacheKey)
170 cacheHash = 0; 170 cacheHash = 0;
171 } else { 171 } else {
172 cacheIterator = presentationAttributeCache().end(); 172 cacheValue = 0;
173 } 173 }
174 174
175 RefPtr<StylePropertySet> style; 175 RefPtr<StylePropertySet> style;
176 if (cacheHash && cacheIterator->value) { 176 if (cacheHash && cacheValue->value) {
177 style = cacheIterator->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 unsigned size = element.attributeCount();
182 for (unsigned i = 0; i < size; ++i) { 182 for (unsigned i = 0; i < size; ++i) {
183 const Attribute* attribute = element.attributeItem(i); 183 const Attribute* attribute = element.attributeItem(i);
184 element.collectStyleForPresentationAttribute(attribute->name(), attr ibute->value(), toMutableStylePropertySet(style)); 184 element.collectStyleForPresentationAttribute(attribute->name(), attr ibute->value(), toMutableStylePropertySet(style));
185 } 185 }
186 } 186 }
187 187
188 if (!cacheHash || cacheIterator->value) 188 if (!cacheHash || cacheValue->value)
189 return style.release(); 189 return style.release();
190 190
191 OwnPtr<PresentationAttributeCacheEntry> newEntry = adoptPtr(new Presentation AttributeCacheEntry); 191 OwnPtr<PresentationAttributeCacheEntry> newEntry = adoptPtr(new Presentation AttributeCacheEntry);
192 newEntry->key = cacheKey; 192 newEntry->key = cacheKey;
193 newEntry->value = style; 193 newEntry->value = style;
194 194
195 static const unsigned presentationAttributeCacheMaximumSize = 4096; 195 static const unsigned presentationAttributeCacheMaximumSize = 4096;
196 if (presentationAttributeCache().size() > presentationAttributeCacheMaximumS ize) { 196 if (presentationAttributeCache().size() > presentationAttributeCacheMaximumS ize) {
197 // FIXME: Discarding the entire cache when it gets too big is probably b ad 197 // 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? 198 // since it creates a perf "cliff". Perhaps we should use an LRU?
199 presentationAttributeCache().clear(); 199 presentationAttributeCache().clear();
200 presentationAttributeCache().set(cacheHash, newEntry.release()); 200 presentationAttributeCache().set(cacheHash, newEntry.release());
201 } else { 201 } else {
202 cacheIterator->value = newEntry.release(); 202 cacheValue->value = newEntry.release();
203 } 203 }
204 204
205 return style.release(); 205 return style.release();
206 } 206 }
207 207
208 } // namespace WebCore 208 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/NodeRareData.h ('k') | Source/core/dom/QualifiedName.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698