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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 Vector<std::pair<StringImpl*, AtomicString>, 3> attributesAndValues; | 49 Vector<std::pair<StringImpl*, AtomicString>, 3> attributesAndValues; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 static bool operator!=(const PresentationAttributeCacheKey& a, const Presentatio nAttributeCacheKey& b) | 52 static bool operator!=(const PresentationAttributeCacheKey& a, const Presentatio nAttributeCacheKey& b) |
| 53 { | 53 { |
| 54 if (a.tagName != b.tagName) | 54 if (a.tagName != b.tagName) |
| 55 return true; | 55 return true; |
| 56 return a.attributesAndValues != b.attributesAndValues; | 56 return a.attributesAndValues != b.attributesAndValues; |
| 57 } | 57 } |
| 58 | 58 |
| 59 struct PresentationAttributeCacheEntry { | 59 struct PresentationAttributeCacheEntry : public NoBaseWillBeGarbageCollectedFina lized<PresentationAttributeCacheEntry> { |
| 60 WTF_MAKE_FAST_ALLOCATED; | 60 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; |
| 61 public: | 61 public: |
| 62 void trace(Visitor* visitor) { visitor->trace(value); } | |
| 63 | |
| 62 PresentationAttributeCacheKey key; | 64 PresentationAttributeCacheKey key; |
| 63 RefPtr<StylePropertySet> value; | 65 RefPtrWillBeMember<StylePropertySet> value; |
| 64 }; | 66 }; |
| 65 | 67 |
| 66 typedef HashMap<unsigned, OwnPtr<PresentationAttributeCacheEntry>, AlreadyHashed > PresentationAttributeCache; | 68 typedef WillBeHeapHashMap<unsigned, OwnPtrWillBeMember<PresentationAttributeCach eEntry>, AlreadyHashed> PresentationAttributeCache; |
| 67 static PresentationAttributeCache& presentationAttributeCache() | 69 static PresentationAttributeCache& presentationAttributeCache() |
| 68 { | 70 { |
| 71 #if ENABLE(OILPAN) | |
| 72 DEFINE_STATIC_LOCAL(Persistent<PresentationAttributeCache>, cache, (new Pres entationAttributeCache())); | |
| 73 return *cache; | |
| 74 #else | |
| 69 DEFINE_STATIC_LOCAL(PresentationAttributeCache, cache, ()); | 75 DEFINE_STATIC_LOCAL(PresentationAttributeCache, cache, ()); |
| 70 return cache; | 76 return cache; |
| 77 #endif // ENABLE(OILPAN) | |
| 71 } | 78 } |
| 72 | 79 |
| 73 class PresentationAttributeCacheCleaner { | 80 class PresentationAttributeCacheCleaner { |
| 74 WTF_MAKE_NONCOPYABLE(PresentationAttributeCacheCleaner); WTF_MAKE_FAST_ALLOC ATED; | 81 WTF_MAKE_NONCOPYABLE(PresentationAttributeCacheCleaner); WTF_MAKE_FAST_ALLOC ATED; |
| 75 public: | 82 public: |
| 76 PresentationAttributeCacheCleaner() | 83 PresentationAttributeCacheCleaner() |
| 77 : m_hitCount(0) | 84 : m_hitCount(0) |
| 78 , m_cleanTimer(this, &PresentationAttributeCacheCleaner::cleanCache) | 85 , m_cleanTimer(this, &PresentationAttributeCacheCleaner::cleanCache) |
| 79 { | 86 { |
| 80 } | 87 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 | 152 |
| 146 static unsigned computePresentationAttributeCacheHash(const PresentationAttribut eCacheKey& key) | 153 static unsigned computePresentationAttributeCacheHash(const PresentationAttribut eCacheKey& key) |
| 147 { | 154 { |
| 148 if (!key.tagName) | 155 if (!key.tagName) |
| 149 return 0; | 156 return 0; |
| 150 ASSERT(key.attributesAndValues.size()); | 157 ASSERT(key.attributesAndValues.size()); |
| 151 unsigned attributeHash = StringHasher::hashMemory(key.attributesAndValues.da ta(), key.attributesAndValues.size() * sizeof(key.attributesAndValues[0])); | 158 unsigned attributeHash = StringHasher::hashMemory(key.attributesAndValues.da ta(), key.attributesAndValues.size() * sizeof(key.attributesAndValues[0])); |
| 152 return WTF::pairIntHash(key.tagName->existingHash(), attributeHash); | 159 return WTF::pairIntHash(key.tagName->existingHash(), attributeHash); |
| 153 } | 160 } |
| 154 | 161 |
| 155 PassRefPtr<StylePropertySet> computePresentationAttributeStyle(Element& element) | 162 PassRefPtrWillBeRawPtr<StylePropertySet> computePresentationAttributeStyle(Eleme nt& element) |
| 156 { | 163 { |
| 157 DEFINE_STATIC_LOCAL(PresentationAttributeCacheCleaner, cacheCleaner, ()); | 164 DEFINE_STATIC_LOCAL(PresentationAttributeCacheCleaner, cacheCleaner, ()); |
| 158 | 165 |
| 159 ASSERT(element.isStyledElement()); | 166 ASSERT(element.isStyledElement()); |
| 160 | 167 |
| 161 PresentationAttributeCacheKey cacheKey; | 168 PresentationAttributeCacheKey cacheKey; |
| 162 makePresentationAttributeCacheKey(element, cacheKey); | 169 makePresentationAttributeCacheKey(element, cacheKey); |
| 163 | 170 |
| 164 unsigned cacheHash = computePresentationAttributeCacheHash(cacheKey); | 171 unsigned cacheHash = computePresentationAttributeCacheHash(cacheKey); |
| 165 | 172 |
| 166 PresentationAttributeCache::ValueType* cacheValue; | 173 PresentationAttributeCacheEntry* cacheEntry; |
| 167 if (cacheHash) { | 174 if (cacheHash) { |
| 168 cacheValue = presentationAttributeCache().add(cacheHash, nullptr).stored Value; | 175 cacheEntry = presentationAttributeCache().get(cacheHash); |
| 169 if (cacheValue->value && cacheValue->value->key != cacheKey) | 176 if (cacheEntry && cacheEntry->key != cacheKey) |
|
esprehn
2014/05/14 20:25:27
Why did you change this? Why doesn't the Oilpan ty
wibling-chromium
2014/05/15 13:15:18
I am not sure I follow? The reason for changing th
| |
| 170 cacheHash = 0; | 177 cacheHash = 0; |
| 171 } else { | 178 } else { |
| 172 cacheValue = 0; | 179 cacheEntry = 0; |
| 173 } | 180 } |
| 174 | 181 |
| 175 RefPtr<StylePropertySet> style; | 182 RefPtrWillBeRawPtr<StylePropertySet> style; |
| 176 if (cacheHash && cacheValue->value) { | 183 if (cacheHash && cacheEntry) { |
| 177 style = cacheValue->value->value; | 184 style = cacheEntry->value; |
| 178 cacheCleaner.didHitPresentationAttributeCache(); | 185 cacheCleaner.didHitPresentationAttributeCache(); |
| 179 } else { | 186 } else { |
| 180 style = MutableStylePropertySet::create(element.isSVGElement() ? SVGAttr ibuteMode : HTMLAttributeMode); | 187 style = MutableStylePropertySet::create(element.isSVGElement() ? SVGAttr ibuteMode : HTMLAttributeMode); |
| 181 unsigned size = element.attributeCount(); | 188 unsigned size = element.attributeCount(); |
| 182 for (unsigned i = 0; i < size; ++i) { | 189 for (unsigned i = 0; i < size; ++i) { |
| 183 const Attribute& attribute = element.attributeItem(i); | 190 const Attribute& attribute = element.attributeItem(i); |
| 184 element.collectStyleForPresentationAttribute(attribute.name(), attri bute.value(), toMutableStylePropertySet(style)); | 191 element.collectStyleForPresentationAttribute(attribute.name(), attri bute.value(), toMutableStylePropertySet(style)); |
| 185 } | 192 } |
| 186 } | 193 } |
| 187 | 194 |
| 188 if (!cacheHash || cacheValue->value) | 195 if (!cacheHash || cacheEntry) |
| 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()); | |
| 201 } else { | |
| 202 cacheValue->value = newEntry.release(); | |
| 203 } | 207 } |
| 208 presentationAttributeCache().set(cacheHash, newEntry.release()); | |
|
esprehn
2014/05/14 20:25:27
This is again wrong, you make us do two hash looku
wibling-chromium
2014/05/15 13:15:18
Yes, this is similar to the previous case where th
| |
| 204 | 209 |
| 205 return style.release(); | 210 return style.release(); |
| 206 } | 211 } |
| 207 | 212 |
| 208 } // namespace WebCore | 213 } // namespace WebCore |
| OLD | NEW |