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

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

Issue 674553002: Move parts of core/dom to C++11 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make Windows shut up when I just try following the style guide Created 6 years, 2 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/dom/Range.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 27 matching lines...) Expand all
38 #include "platform/Timer.h" 38 #include "platform/Timer.h"
39 #include "wtf/HashFunctions.h" 39 #include "wtf/HashFunctions.h"
40 #include "wtf/HashMap.h" 40 #include "wtf/HashMap.h"
41 #include "wtf/text/CString.h" 41 #include "wtf/text/CString.h"
42 42
43 namespace blink { 43 namespace blink {
44 44
45 using namespace HTMLNames; 45 using namespace HTMLNames;
46 46
47 struct PresentationAttributeCacheKey { 47 struct PresentationAttributeCacheKey {
48 PresentationAttributeCacheKey() : tagName(0) { } 48 PresentationAttributeCacheKey() : tagName(nullptr) { }
49 StringImpl* tagName; 49 StringImpl* tagName;
50 Vector<std::pair<StringImpl*, AtomicString>, 3> attributesAndValues; 50 Vector<std::pair<StringImpl*, AtomicString>, 3> attributesAndValues;
51 }; 51 };
52 52
53 static bool operator!=(const PresentationAttributeCacheKey& a, const Presentatio nAttributeCacheKey& b) 53 static bool operator!=(const PresentationAttributeCacheKey& a, const Presentatio nAttributeCacheKey& b)
54 { 54 {
55 if (a.tagName != b.tagName) 55 if (a.tagName != b.tagName)
56 return true; 56 return true;
57 return a.attributesAndValues != b.attributesAndValues; 57 return a.attributesAndValues != b.attributesAndValues;
58 } 58 }
59 59
60 struct PresentationAttributeCacheEntry final : public NoBaseWillBeGarbageCollect edFinalized<PresentationAttributeCacheEntry> { 60 struct PresentationAttributeCacheEntry final : public NoBaseWillBeGarbageCollect edFinalized<PresentationAttributeCacheEntry> {
61 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; 61 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
62 public: 62 public:
63 void trace(Visitor* visitor) { visitor->trace(value); } 63 void trace(Visitor* visitor) { visitor->trace(value); }
64 64
65 PresentationAttributeCacheKey key; 65 PresentationAttributeCacheKey key;
66 RefPtrWillBeMember<StylePropertySet> value; 66 RefPtrWillBeMember<StylePropertySet> value;
67 }; 67 };
68 68
69 typedef WillBeHeapHashMap<unsigned, OwnPtrWillBeMember<PresentationAttributeCach eEntry>, AlreadyHashed> PresentationAttributeCache; 69 using PresentationAttributeCache = WillBeHeapHashMap<unsigned, OwnPtrWillBeMembe r<PresentationAttributeCacheEntry>, AlreadyHashed>;
70 static PresentationAttributeCache& presentationAttributeCache() 70 static PresentationAttributeCache& presentationAttributeCache()
71 { 71 {
72 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<PresentationAttributeCache>, cach e, (adoptPtrWillBeNoop(new PresentationAttributeCache()))); 72 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<PresentationAttributeCache>, cach e, (adoptPtrWillBeNoop(new PresentationAttributeCache())));
73 return *cache; 73 return *cache;
74 } 74 }
75 75
76 class PresentationAttributeCacheCleaner { 76 class PresentationAttributeCacheCleaner {
77 WTF_MAKE_NONCOPYABLE(PresentationAttributeCacheCleaner); WTF_MAKE_FAST_ALLOC ATED; 77 WTF_MAKE_NONCOPYABLE(PresentationAttributeCacheCleaner); WTF_MAKE_FAST_ALLOC ATED;
78 public: 78 public:
79 PresentationAttributeCacheCleaner() 79 PresentationAttributeCacheCleaner()
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 static void makePresentationAttributeCacheKey(Element& element, PresentationAttr ibuteCacheKey& result) 121 static void makePresentationAttributeCacheKey(Element& element, PresentationAttr ibuteCacheKey& result)
122 { 122 {
123 // FIXME: Enable for SVG. 123 // FIXME: Enable for SVG.
124 if (!element.isHTMLElement()) 124 if (!element.isHTMLElement())
125 return; 125 return;
126 // Interpretation of the size attributes on <input> depends on the type attr ibute. 126 // Interpretation of the size attributes on <input> depends on the type attr ibute.
127 if (isHTMLInputElement(element)) 127 if (isHTMLInputElement(element))
128 return; 128 return;
129 AttributeCollection attributes = element.attributesWithoutUpdate(); 129 AttributeCollection attributes = element.attributesWithoutUpdate();
130 AttributeCollection::iterator end = attributes.end(); 130 for (const Attribute& attr : attributes) {
131 for (AttributeCollection::iterator it = attributes.begin(); it != end; ++it) { 131 if (!element.isPresentationAttribute(attr.name()))
132 if (!element.isPresentationAttribute(it->name()))
133 continue; 132 continue;
134 if (!it->namespaceURI().isNull()) 133 if (!attr.namespaceURI().isNull())
135 return; 134 return;
136 // FIXME: Background URL may depend on the base URL and can't be shared. Disallow caching. 135 // FIXME: Background URL may depend on the base URL and can't be shared. Disallow caching.
137 if (it->name() == backgroundAttr) 136 if (attr.name() == backgroundAttr)
138 return; 137 return;
139 result.attributesAndValues.append(std::make_pair(it->localName().impl(), it->value())); 138 result.attributesAndValues.append(std::make_pair(attr.localName().impl() , attr.value()));
140 } 139 }
141 if (result.attributesAndValues.isEmpty()) 140 if (result.attributesAndValues.isEmpty())
142 return; 141 return;
143 // Attribute order doesn't matter. Sort for easy equality comparison. 142 // Attribute order doesn't matter. Sort for easy equality comparison.
144 std::sort(result.attributesAndValues.begin(), result.attributesAndValues.end (), attributeNameSort); 143 std::sort(result.attributesAndValues.begin(), result.attributesAndValues.end (), attributeNameSort);
145 // The cache key is non-null when the tagName is set. 144 // The cache key is non-null when the tagName is set.
146 result.tagName = element.localName().impl(); 145 result.tagName = element.localName().impl();
147 } 146 }
148 147
149 static unsigned computePresentationAttributeCacheHash(const PresentationAttribut eCacheKey& key) 148 static unsigned computePresentationAttributeCacheHash(const PresentationAttribut eCacheKey& key)
(...skipping 15 matching lines...) Expand all
165 makePresentationAttributeCacheKey(element, cacheKey); 164 makePresentationAttributeCacheKey(element, cacheKey);
166 165
167 unsigned cacheHash = computePresentationAttributeCacheHash(cacheKey); 166 unsigned cacheHash = computePresentationAttributeCacheHash(cacheKey);
168 167
169 PresentationAttributeCache::ValueType* cacheValue; 168 PresentationAttributeCache::ValueType* cacheValue;
170 if (cacheHash) { 169 if (cacheHash) {
171 cacheValue = presentationAttributeCache().add(cacheHash, nullptr).stored Value; 170 cacheValue = presentationAttributeCache().add(cacheHash, nullptr).stored Value;
172 if (cacheValue->value && cacheValue->value->key != cacheKey) 171 if (cacheValue->value && cacheValue->value->key != cacheKey)
173 cacheHash = 0; 172 cacheHash = 0;
174 } else { 173 } else {
175 cacheValue = 0; 174 cacheValue = nullptr;
176 } 175 }
177 176
178 RefPtrWillBeRawPtr<StylePropertySet> style = nullptr; 177 RefPtrWillBeRawPtr<StylePropertySet> style = nullptr;
179 if (cacheHash && cacheValue->value) { 178 if (cacheHash && cacheValue->value) {
180 style = cacheValue->value->value; 179 style = cacheValue->value->value;
181 cacheCleaner.didHitPresentationAttributeCache(); 180 cacheCleaner.didHitPresentationAttributeCache();
182 } else { 181 } else {
183 style = MutableStylePropertySet::create(element.isSVGElement() ? SVGAttr ibuteMode : HTMLAttributeMode); 182 style = MutableStylePropertySet::create(element.isSVGElement() ? SVGAttr ibuteMode : HTMLAttributeMode);
184 AttributeCollection attributes = element.attributesWithoutUpdate(); 183 AttributeCollection attributes = element.attributesWithoutUpdate();
185 AttributeCollection::iterator end = attributes.end(); 184 for (const Attribute& attr : attributes)
186 for (AttributeCollection::iterator it = attributes.begin(); it != end; + +it) 185 element.collectStyleForPresentationAttribute(attr.name(), attr.value (), toMutableStylePropertySet(style));
187 element.collectStyleForPresentationAttribute(it->name(), it->value() , toMutableStylePropertySet(style));
188 } 186 }
189 187
190 if (!cacheHash || cacheValue->value) 188 if (!cacheHash || cacheValue->value)
191 return style.release(); 189 return style.release();
192 190
193 OwnPtrWillBeRawPtr<PresentationAttributeCacheEntry> newEntry = adoptPtrWillB eNoop(new PresentationAttributeCacheEntry); 191 OwnPtrWillBeRawPtr<PresentationAttributeCacheEntry> newEntry = adoptPtrWillB eNoop(new PresentationAttributeCacheEntry);
194 newEntry->key = cacheKey; 192 newEntry->key = cacheKey;
195 newEntry->value = style; 193 newEntry->value = style;
196 194
197 static const unsigned presentationAttributeCacheMaximumSize = 4096; 195 static const unsigned presentationAttributeCacheMaximumSize = 4096;
198 if (presentationAttributeCache().size() > presentationAttributeCacheMaximumS ize) { 196 if (presentationAttributeCache().size() > presentationAttributeCacheMaximumS ize) {
199 // 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
200 // 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?
201 presentationAttributeCache().clear(); 199 presentationAttributeCache().clear();
202 presentationAttributeCache().set(cacheHash, newEntry.release()); 200 presentationAttributeCache().set(cacheHash, newEntry.release());
203 } else { 201 } else {
204 cacheValue->value = newEntry.release(); 202 cacheValue->value = newEntry.release();
205 } 203 }
206 204
207 return style.release(); 205 return style.release();
208 } 206 }
209 207
210 } // namespace blink 208 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/Node.cpp ('k') | Source/core/dom/Range.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698