Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
| 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
| 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. |
| 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) |
| 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 } | 47 } |
| 48 | 48 |
| 49 void CachedMatchedProperties::clear() | 49 void CachedMatchedProperties::clear() |
| 50 { | 50 { |
| 51 matchedProperties.clear(); | 51 matchedProperties.clear(); |
| 52 renderStyle = nullptr; | 52 renderStyle = nullptr; |
| 53 parentRenderStyle = nullptr; | 53 parentRenderStyle = nullptr; |
| 54 } | 54 } |
| 55 | 55 |
| 56 MatchedPropertiesCache::MatchedPropertiesCache() | 56 MatchedPropertiesCache::MatchedPropertiesCache() |
| 57 #if !ENABLE(OILPAN) | |
| 57 : m_additionsSinceLastSweep(0) | 58 : m_additionsSinceLastSweep(0) |
| 58 , m_sweepTimer(this, &MatchedPropertiesCache::sweep) | 59 , m_sweepTimer(this, &MatchedPropertiesCache::sweep) |
| 60 #endif | |
| 59 { | 61 { |
| 60 } | 62 } |
| 61 | 63 |
| 62 const CachedMatchedProperties* MatchedPropertiesCache::find(unsigned hash, const StyleResolverState& styleResolverState, const MatchResult& matchResult) | 64 const CachedMatchedProperties* MatchedPropertiesCache::find(unsigned hash, const StyleResolverState& styleResolverState, const MatchResult& matchResult) |
| 63 { | 65 { |
| 64 ASSERT(hash); | 66 ASSERT(hash); |
| 65 | 67 |
| 66 Cache::iterator it = m_cache.find(hash); | 68 Cache::iterator it = m_cache.find(hash); |
| 67 if (it == m_cache.end()) | 69 if (it == m_cache.end()) |
| 68 return 0; | 70 return 0; |
| 69 CachedMatchedProperties* cacheItem = it->value.get(); | 71 CachedMatchedProperties* cacheItem = it->value.get(); |
| 70 ASSERT(cacheItem); | 72 ASSERT(cacheItem); |
| 71 | 73 |
| 72 size_t size = matchResult.matchedProperties.size(); | 74 size_t size = matchResult.matchedProperties.size(); |
| 73 if (size != cacheItem->matchedProperties.size()) | 75 if (size != cacheItem->matchedProperties.size()) |
| 74 return 0; | 76 return 0; |
| 75 if (cacheItem->renderStyle->insideLink() != styleResolverState.style()->insi deLink()) | 77 if (cacheItem->renderStyle->insideLink() != styleResolverState.style()->insi deLink()) |
| 76 return 0; | 78 return 0; |
| 77 for (size_t i = 0; i < size; ++i) { | 79 for (size_t i = 0; i < size; ++i) { |
| 78 if (matchResult.matchedProperties[i] != cacheItem->matchedProperties[i]) | 80 if (matchResult.matchedProperties[i] != cacheItem->matchedProperties[i]) |
| 79 return 0; | 81 return 0; |
| 80 } | 82 } |
| 81 if (cacheItem->ranges != matchResult.ranges) | 83 if (cacheItem->ranges != matchResult.ranges) |
| 82 return 0; | 84 return 0; |
| 83 return cacheItem; | 85 return cacheItem; |
| 84 } | 86 } |
| 85 | 87 |
| 86 void MatchedPropertiesCache::add(const RenderStyle* style, const RenderStyle* pa rentStyle, unsigned hash, const MatchResult& matchResult) | 88 void MatchedPropertiesCache::add(const RenderStyle* style, const RenderStyle* pa rentStyle, unsigned hash, const MatchResult& matchResult) |
| 87 { | 89 { |
| 90 #if !ENABLE(OILPAN) | |
| 88 static const unsigned maxAdditionsBetweenSweeps = 100; | 91 static const unsigned maxAdditionsBetweenSweeps = 100; |
| 89 if (++m_additionsSinceLastSweep >= maxAdditionsBetweenSweeps | 92 if (++m_additionsSinceLastSweep >= maxAdditionsBetweenSweeps |
| 90 && !m_sweepTimer.isActive()) { | 93 && !m_sweepTimer.isActive()) { |
| 91 static const unsigned sweepTimeInSeconds = 60; | 94 static const unsigned sweepTimeInSeconds = 60; |
| 92 m_sweepTimer.startOneShot(sweepTimeInSeconds, FROM_HERE); | 95 m_sweepTimer.startOneShot(sweepTimeInSeconds, FROM_HERE); |
| 93 } | 96 } |
| 97 #endif | |
| 94 | 98 |
| 95 ASSERT(hash); | 99 ASSERT(hash); |
| 96 Cache::AddResult addResult = m_cache.add(hash, nullptr); | 100 Cache::AddResult addResult = m_cache.add(hash, nullptr); |
| 97 if (addResult.isNewEntry) | 101 if (addResult.isNewEntry) |
| 98 addResult.storedValue->value = adoptPtr(new CachedMatchedProperties); | 102 addResult.storedValue->value = adoptPtrWillBeNoop(new CachedMatchedPrope rties); |
| 99 | 103 |
| 100 CachedMatchedProperties* cacheItem = addResult.storedValue->value.get(); | 104 CachedMatchedProperties* cacheItem = addResult.storedValue->value.get(); |
| 101 if (!addResult.isNewEntry) | 105 if (!addResult.isNewEntry) |
| 102 cacheItem->clear(); | 106 cacheItem->clear(); |
| 103 | 107 |
| 104 cacheItem->set(style, parentStyle, matchResult); | 108 cacheItem->set(style, parentStyle, matchResult); |
| 105 } | 109 } |
| 106 | 110 |
| 107 void MatchedPropertiesCache::clear() | 111 void MatchedPropertiesCache::clear() |
| 108 { | 112 { |
| 109 m_cache.clear(); | 113 m_cache.clear(); |
| 110 } | 114 } |
| 111 | 115 |
| 112 void MatchedPropertiesCache::clearViewportDependent() | 116 void MatchedPropertiesCache::clearViewportDependent() |
| 113 { | 117 { |
| 114 Vector<unsigned, 16> toRemove; | 118 WillBeHeapVector<unsigned, 16> toRemove; |
|
haraken
2014/06/25 13:37:11
Shall we revert this back to a off-heap Vector, si
wibling-chromium
2014/06/26 09:30:59
Done.
| |
| 115 for (Cache::iterator it = m_cache.begin(); it != m_cache.end(); ++it) { | 119 for (Cache::iterator it = m_cache.begin(); it != m_cache.end(); ++it) { |
| 116 CachedMatchedProperties* cacheItem = it->value.get(); | 120 CachedMatchedProperties* cacheItem = it->value.get(); |
| 117 if (cacheItem->renderStyle->hasViewportUnits()) | 121 if (cacheItem->renderStyle->hasViewportUnits()) |
| 118 toRemove.append(it->key); | 122 toRemove.append(it->key); |
| 119 } | 123 } |
| 120 m_cache.removeAll(toRemove); | 124 m_cache.removeAll(toRemove); |
| 121 } | 125 } |
| 122 | 126 |
| 127 #if !ENABLE(OILPAN) | |
| 123 void MatchedPropertiesCache::sweep(Timer<MatchedPropertiesCache>*) | 128 void MatchedPropertiesCache::sweep(Timer<MatchedPropertiesCache>*) |
| 124 { | 129 { |
| 125 // Look for cache entries containing a style declaration with a single ref a nd remove them. | 130 // Look for cache entries containing a style declaration with a single ref a nd remove them. |
| 126 // This may happen when an element attribute mutation causes it to generate a new inlineStyle() | 131 // This may happen when an element attribute mutation causes it to generate a new inlineStyle() |
| 127 // or presentationAttributeStyle(), potentially leaving this cache with the last ref on the old one. | 132 // or presentationAttributeStyle(), potentially leaving this cache with the last ref on the old one. |
| 128 Vector<unsigned, 16> toRemove; | 133 Vector<unsigned, 16> toRemove; |
| 129 Cache::iterator it = m_cache.begin(); | 134 Cache::iterator it = m_cache.begin(); |
| 130 Cache::iterator end = m_cache.end(); | 135 Cache::iterator end = m_cache.end(); |
| 131 for (; it != end; ++it) { | 136 for (; it != end; ++it) { |
| 132 CachedMatchedProperties* cacheItem = it->value.get(); | 137 CachedMatchedProperties* cacheItem = it->value.get(); |
| 133 Vector<MatchedProperties>& matchedProperties = cacheItem->matchedPropert ies; | 138 Vector<MatchedProperties>& matchedProperties = cacheItem->matchedPropert ies; |
| 134 for (size_t i = 0; i < matchedProperties.size(); ++i) { | 139 for (size_t i = 0; i < matchedProperties.size(); ++i) { |
| 135 if (matchedProperties[i].properties->hasOneRef()) { | 140 if (matchedProperties[i].properties->hasOneRef()) { |
| 136 toRemove.append(it->key); | 141 toRemove.append(it->key); |
| 137 break; | 142 break; |
| 138 } | 143 } |
| 139 } | 144 } |
| 140 } | 145 } |
| 141 m_cache.removeAll(toRemove); | 146 m_cache.removeAll(toRemove); |
| 142 m_additionsSinceLastSweep = 0; | 147 m_additionsSinceLastSweep = 0; |
| 143 } | 148 } |
| 149 #endif | |
| 144 | 150 |
| 145 bool MatchedPropertiesCache::isCacheable(const Element* element, const RenderSty le* style, const RenderStyle* parentStyle) | 151 bool MatchedPropertiesCache::isCacheable(const Element* element, const RenderSty le* style, const RenderStyle* parentStyle) |
| 146 { | 152 { |
| 147 // FIXME: CSSPropertyWebkitWritingMode modifies state when applying to docum ent element. We can't skip the applying by caching. | 153 // FIXME: CSSPropertyWebkitWritingMode modifies state when applying to docum ent element. We can't skip the applying by caching. |
| 148 if (element == element->document().documentElement() && element->document(). writingModeSetOnDocumentElement()) | 154 if (element == element->document().documentElement() && element->document(). writingModeSetOnDocumentElement()) |
| 149 return false; | 155 return false; |
| 150 if (style->unique() || (style->styleType() != NOPSEUDO && parentStyle->uniqu e())) | 156 if (style->unique() || (style->styleType() != NOPSEUDO && parentStyle->uniqu e())) |
| 151 return false; | 157 return false; |
| 152 if (style->hasAppearance()) | 158 if (style->hasAppearance()) |
| 153 return false; | 159 return false; |
| 154 if (style->zoom() != RenderStyle::initialZoom()) | 160 if (style->zoom() != RenderStyle::initialZoom()) |
| 155 return false; | 161 return false; |
| 156 if (style->writingMode() != RenderStyle::initialWritingMode()) | 162 if (style->writingMode() != RenderStyle::initialWritingMode()) |
| 157 return false; | 163 return false; |
| 158 if (style->hasCurrentColor()) | 164 if (style->hasCurrentColor()) |
| 159 return false; | 165 return false; |
| 160 // CSSPropertyInternalCallback sets the rule's selector name into the Render Style, and that's not recalculated if the RenderStyle is loaded from the cache, so don't cache it. | 166 // CSSPropertyInternalCallback sets the rule's selector name into the Render Style, and that's not recalculated if the RenderStyle is loaded from the cache, so don't cache it. |
| 161 if (!style->callbackSelectors().isEmpty()) | 167 if (!style->callbackSelectors().isEmpty()) |
| 162 return false; | 168 return false; |
| 163 // The cache assumes static knowledge about which properties are inherited. | 169 // The cache assumes static knowledge about which properties are inherited. |
| 164 if (parentStyle->hasExplicitlyInheritedProperties()) | 170 if (parentStyle->hasExplicitlyInheritedProperties()) |
| 165 return false; | 171 return false; |
| 166 return true; | 172 return true; |
| 167 } | 173 } |
| 168 | 174 |
| 175 void MatchedPropertiesCache::trace(Visitor* visitor) | |
| 176 { | |
| 177 visitor->trace(m_cache); | |
| 169 } | 178 } |
| 179 | |
| 180 } | |
| OLD | NEW |