Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 { | 60 struct PresentationAttributeCacheEntry : public NoBaseWillBeGarbageCollectedFina lized<PresentationAttributeCacheEntry> { |
|
zerny-chromium
2014/06/25 06:19:02
Nit: FINAL
wibling-chromium
2014/06/25 09:03:28
Done.
| |
| 61 WTF_MAKE_FAST_ALLOCATED; | 61 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; |
| 62 public: | 62 public: |
| 63 void trace(Visitor* visitor) { visitor->trace(value); } | |
| 64 | |
| 63 PresentationAttributeCacheKey key; | 65 PresentationAttributeCacheKey key; |
| 64 RefPtr<StylePropertySet> value; | 66 RefPtrWillBeMember<StylePropertySet> value; |
| 65 }; | 67 }; |
| 66 | 68 |
| 67 typedef HashMap<unsigned, OwnPtr<PresentationAttributeCacheEntry>, AlreadyHashed > PresentationAttributeCache; | 69 typedef WillBeHeapHashMap<unsigned, OwnPtrWillBeMember<PresentationAttributeCach eEntry>, AlreadyHashed> PresentationAttributeCache; |
| 68 static PresentationAttributeCache& presentationAttributeCache() | 70 static PresentationAttributeCache& presentationAttributeCache() |
| 69 { | 71 { |
| 72 #if ENABLE(OILPAN) | |
| 73 DEFINE_STATIC_LOCAL(Persistent<PresentationAttributeCache>, cache, (new Pres entationAttributeCache())); | |
| 74 return *cache; | |
| 75 #else | |
| 70 DEFINE_STATIC_LOCAL(PresentationAttributeCache, cache, ()); | 76 DEFINE_STATIC_LOCAL(PresentationAttributeCache, cache, ()); |
| 71 return cache; | 77 return cache; |
| 78 #endif // ENABLE(OILPAN) | |
| 72 } | 79 } |
| 73 | 80 |
| 74 class PresentationAttributeCacheCleaner { | 81 class PresentationAttributeCacheCleaner { |
| 75 WTF_MAKE_NONCOPYABLE(PresentationAttributeCacheCleaner); WTF_MAKE_FAST_ALLOC ATED; | 82 WTF_MAKE_NONCOPYABLE(PresentationAttributeCacheCleaner); WTF_MAKE_FAST_ALLOC ATED; |
| 76 public: | 83 public: |
| 77 PresentationAttributeCacheCleaner() | 84 PresentationAttributeCacheCleaner() |
| 78 : m_hitCount(0) | 85 : m_hitCount(0) |
| 79 , m_cleanTimer(this, &PresentationAttributeCacheCleaner::cleanCache) | 86 , m_cleanTimer(this, &PresentationAttributeCacheCleaner::cleanCache) |
| 80 { | 87 { |
| 81 } | 88 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 | 153 |
| 147 static unsigned computePresentationAttributeCacheHash(const PresentationAttribut eCacheKey& key) | 154 static unsigned computePresentationAttributeCacheHash(const PresentationAttribut eCacheKey& key) |
| 148 { | 155 { |
| 149 if (!key.tagName) | 156 if (!key.tagName) |
| 150 return 0; | 157 return 0; |
| 151 ASSERT(key.attributesAndValues.size()); | 158 ASSERT(key.attributesAndValues.size()); |
| 152 unsigned attributeHash = StringHasher::hashMemory(key.attributesAndValues.da ta(), key.attributesAndValues.size() * sizeof(key.attributesAndValues[0])); | 159 unsigned attributeHash = StringHasher::hashMemory(key.attributesAndValues.da ta(), key.attributesAndValues.size() * sizeof(key.attributesAndValues[0])); |
| 153 return WTF::pairIntHash(key.tagName->existingHash(), attributeHash); | 160 return WTF::pairIntHash(key.tagName->existingHash(), attributeHash); |
| 154 } | 161 } |
| 155 | 162 |
| 156 PassRefPtr<StylePropertySet> computePresentationAttributeStyle(Element& element) | 163 PassRefPtrWillBeRawPtr<StylePropertySet> computePresentationAttributeStyle(Eleme nt& element) |
| 157 { | 164 { |
| 158 DEFINE_STATIC_LOCAL(PresentationAttributeCacheCleaner, cacheCleaner, ()); | 165 DEFINE_STATIC_LOCAL(PresentationAttributeCacheCleaner, cacheCleaner, ()); |
| 159 | 166 |
| 160 ASSERT(element.isStyledElement()); | 167 ASSERT(element.isStyledElement()); |
| 161 | 168 |
| 162 PresentationAttributeCacheKey cacheKey; | 169 PresentationAttributeCacheKey cacheKey; |
| 163 makePresentationAttributeCacheKey(element, cacheKey); | 170 makePresentationAttributeCacheKey(element, cacheKey); |
| 164 | 171 |
| 165 unsigned cacheHash = computePresentationAttributeCacheHash(cacheKey); | 172 unsigned cacheHash = computePresentationAttributeCacheHash(cacheKey); |
| 166 | 173 |
| 167 PresentationAttributeCache::ValueType* cacheValue; | 174 PresentationAttributeCache::ValueType* cacheValue; |
| 168 if (cacheHash) { | 175 if (cacheHash) { |
| 169 cacheValue = presentationAttributeCache().add(cacheHash, nullptr).stored Value; | 176 cacheValue = presentationAttributeCache().add(cacheHash, nullptr).stored Value; |
| 170 if (cacheValue->value && cacheValue->value->key != cacheKey) | 177 if (cacheValue->value && cacheValue->value->key != cacheKey) |
| 171 cacheHash = 0; | 178 cacheHash = 0; |
| 172 } else { | 179 } else { |
| 173 cacheValue = 0; | 180 cacheValue = 0; |
| 174 } | 181 } |
| 175 | 182 |
| 176 RefPtr<StylePropertySet> style; | 183 RefPtrWillBeRawPtr<StylePropertySet> style; |
| 177 if (cacheHash && cacheValue->value) { | 184 if (cacheHash && cacheValue->value) { |
| 178 style = cacheValue->value->value; | 185 style = cacheValue->value->value; |
| 179 cacheCleaner.didHitPresentationAttributeCache(); | 186 cacheCleaner.didHitPresentationAttributeCache(); |
| 180 } else { | 187 } else { |
| 181 style = MutableStylePropertySet::create(element.isSVGElement() ? SVGAttr ibuteMode : HTMLAttributeMode); | 188 style = MutableStylePropertySet::create(element.isSVGElement() ? SVGAttr ibuteMode : HTMLAttributeMode); |
| 182 AttributeCollection attributes = element.attributes(); | 189 AttributeCollection attributes = element.attributes(); |
| 183 AttributeCollection::const_iterator end = attributes.end(); | 190 AttributeCollection::const_iterator end = attributes.end(); |
| 184 for (AttributeCollection::const_iterator it = attributes.begin(); it != end; ++it) | 191 for (AttributeCollection::const_iterator it = attributes.begin(); it != end; ++it) |
| 185 element.collectStyleForPresentationAttribute(it->name(), it->value() , toMutableStylePropertySet(style)); | 192 element.collectStyleForPresentationAttribute(it->name(), it->value() , toMutableStylePropertySet(style)); |
| 186 } | 193 } |
| 187 | 194 |
| 188 if (!cacheHash || cacheValue->value) | 195 if (!cacheHash || cacheValue->value) |
| 189 return style.release(); | 196 return style.release(); |
| 190 | 197 |
| 191 OwnPtr<PresentationAttributeCacheEntry> newEntry = adoptPtr(new Presentation AttributeCacheEntry); | 198 OwnPtrWillBeRawPtr<PresentationAttributeCacheEntry> newEntry = adoptPtrWillB eNoop(new PresentationAttributeCacheEntry); |
| 192 newEntry->key = cacheKey; | 199 newEntry->key = cacheKey; |
| 193 newEntry->value = style; | 200 newEntry->value = style; |
| 194 | 201 |
| 195 static const unsigned presentationAttributeCacheMaximumSize = 4096; | 202 static const unsigned presentationAttributeCacheMaximumSize = 4096; |
| 196 if (presentationAttributeCache().size() > presentationAttributeCacheMaximumS ize) { | 203 if (presentationAttributeCache().size() > presentationAttributeCacheMaximumS ize) { |
| 197 // FIXME: Discarding the entire cache when it gets too big is probably b ad | 204 // 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? | 205 // since it creates a perf "cliff". Perhaps we should use an LRU? |
| 199 presentationAttributeCache().clear(); | 206 presentationAttributeCache().clear(); |
| 200 presentationAttributeCache().set(cacheHash, newEntry.release()); | 207 presentationAttributeCache().set(cacheHash, newEntry.release()); |
| 201 } else { | 208 } else { |
| 202 cacheValue->value = newEntry.release(); | 209 cacheValue->value =newEntry.release(); |
|
zerny-chromium
2014/06/25 06:19:02
Nit: unintended edit
wibling-chromium
2014/06/25 09:03:28
Done.
| |
| 203 } | 210 } |
| 204 | 211 |
| 205 return style.release(); | 212 return style.release(); |
| 206 } | 213 } |
| 207 | 214 |
| 208 } // namespace WebCore | 215 } // namespace WebCore |
| OLD | NEW |