Changeset 252208 in webkit
- Timestamp:
- Nov 7, 2019 3:01:20 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r252207 r252208 1 2019-11-07 Antti Koivisto <antti@apple.com> 2 3 Factor matched declarations cache into a class 4 https://bugs.webkit.org/show_bug.cgi?id=203972 5 6 Reviewed by Zalan Bujtas. 7 8 Move the code out from StyleResolver and rename "matched properties cache" -> "matched declarations cache" 9 to better describe it. 10 11 * Sources.txt: 12 * WebCore.xcodeproj/project.pbxproj: 13 * css/ElementRuleCollector.cpp: 14 (WebCore::ElementRuleCollector::declarationsForOrigin): 15 16 Add a helper. 17 18 (WebCore::ElementRuleCollector::transferMatchedRules): 19 20 Reserve vector capacity before adding rules. 21 22 (WebCore::ElementRuleCollector::addMatchedProperties): 23 * css/ElementRuleCollector.h: 24 (WebCore::MatchResult::operator== const): 25 (WebCore::MatchResult::operator!= const): 26 27 Remove the unneeded inline capacity so we can just use MatchResult itself in the cache. 28 29 * css/RuleSet.cpp: 30 (WebCore::RuleSet::addChildRules): 31 * css/StyleResolver.cpp: 32 (WebCore::StyleResolver::StyleResolver): 33 (WebCore::StyleResolver::invalidateMatchedDeclarationsCache): 34 (WebCore::StyleResolver::clearCachedDeclarationsAffectedByViewportUnits): 35 (WebCore::StyleResolver::applyMatchedProperties): 36 (WebCore::StyleResolver::sweepMatchedPropertiesCache): Deleted. 37 (WebCore::StyleResolver::computeMatchedPropertiesHash): Deleted. 38 (WebCore::StyleResolver::findFromMatchedPropertiesCache): Deleted. 39 (WebCore::StyleResolver::addToMatchedPropertiesCache): Deleted. 40 (WebCore::StyleResolver::invalidateMatchedPropertiesCache): Deleted. 41 (WebCore::StyleResolver::clearCachedPropertiesAffectedByViewportUnits): Deleted. 42 (WebCore::isCacheableInMatchedPropertiesCache): Deleted. 43 * css/StyleResolver.h: 44 (WebCore::StyleResolver::MatchedPropertiesCacheItem::MatchedPropertiesCacheItem): Deleted. 45 * dom/Document.cpp: 46 (WebCore::Document::invalidateMatchedPropertiesCacheAndForceStyleRecalc): 47 (WebCore::Document::updateViewportUnitsOnResize): 48 * page/Page.cpp: 49 (WebCore::Page::updateStyleAfterChangeInEnvironment): 50 * style/MatchedDeclarationsCache.cpp: Added. 51 (WebCore::Style::MatchedDeclarationsCache::MatchedDeclarationsCache): 52 (WebCore::Style::MatchedDeclarationsCache::isCacheable): 53 (WebCore::Style::MatchedDeclarationsCache::computeHash): 54 (WebCore::Style::MatchedDeclarationsCache::find): 55 (WebCore::Style::MatchedDeclarationsCache::add): 56 (WebCore::Style::MatchedDeclarationsCache::invalidate): 57 (WebCore::Style::MatchedDeclarationsCache::clearEntriesAffectedByViewportUnits): 58 (WebCore::Style::MatchedDeclarationsCache::sweep): 59 * style/MatchedDeclarationsCache.h: Added. 60 * style/StyleTreeResolver.cpp: 61 (WebCore::Style::TreeResolver::resolveElement): 62 1 63 2019-11-07 Eric Carlson <eric.carlson@apple.com> 2 64 -
trunk/Source/WebCore/Sources.txt
r252036 r252208 2345 2345 style/IdChangeInvalidation.cpp 2346 2346 style/InlineTextBoxStyle.cpp 2347 style/MatchedDeclarationsCache.cpp 2347 2348 style/PropertyCascade.cpp 2348 2349 style/StyleBuilder.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r252036 r252208 4810 4810 E44FA1851BCA6B5A0091B6EF /* ComposedTreeIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E44FA1841BCA6B5A0091B6EF /* ComposedTreeIterator.h */; }; 4811 4811 E45322AC140CE267005A0F92 /* SelectorQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = E45322AA140CE267005A0F92 /* SelectorQuery.h */; }; 4812 E45BA6AA2374926C004DFC07 /* MatchedDeclarationsCache.h in Headers */ = {isa = PBXBuildFile; fileRef = E45BA6A82374926B004DFC07 /* MatchedDeclarationsCache.h */; }; 4812 4813 E4605FEC2166480900E53046 /* PrewarmInformation.h in Headers */ = {isa = PBXBuildFile; fileRef = E4605FEA2166480800E53046 /* PrewarmInformation.h */; settings = {ATTRIBUTES = (Private, ); }; }; 4813 4814 E461802D1C8DD2900026C02C /* StyleRelations.h in Headers */ = {isa = PBXBuildFile; fileRef = E461802C1C8DD2900026C02C /* StyleRelations.h */; }; … … 15121 15122 E453903C0EAFD637003695C8 /* WidgetIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WidgetIOS.mm; sourceTree = "<group>"; }; 15122 15123 E45390AD0EAFF4B5003695C8 /* SystemMemoryIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SystemMemoryIOS.cpp; sourceTree = "<group>"; }; 15124 E45BA6A82374926B004DFC07 /* MatchedDeclarationsCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MatchedDeclarationsCache.h; sourceTree = "<group>"; }; 15125 E45BA6AB2374927B004DFC07 /* MatchedDeclarationsCache.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MatchedDeclarationsCache.cpp; sourceTree = "<group>"; }; 15123 15126 E4605FEA2166480800E53046 /* PrewarmInformation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrewarmInformation.h; sourceTree = "<group>"; }; 15124 15127 E461802C1C8DD2900026C02C /* StyleRelations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleRelations.h; sourceTree = "<group>"; }; … … 26962 26965 1C0106FE192594DF008A4201 /* InlineTextBoxStyle.cpp */, 26963 26966 1C0106FF192594DF008A4201 /* InlineTextBoxStyle.h */, 26967 E45BA6AB2374927B004DFC07 /* MatchedDeclarationsCache.cpp */, 26968 E45BA6A82374926B004DFC07 /* MatchedDeclarationsCache.h */, 26964 26969 E4ABABE52361A34200FA4345 /* PropertyCascade.cpp */, 26965 26970 E4ABABE22361A32900FA4345 /* PropertyCascade.h */, … … 30640 30645 FDF6BAF9134A4C9800822920 /* JSOfflineAudioCompletionEvent.h in Headers */, 30641 30646 FDA9326716703BA9008982DC /* JSOfflineAudioContext.h in Headers */, 30647 E45BA6AA2374926C004DFC07 /* MatchedDeclarationsCache.h in Headers */, 30642 30648 314877E61FAAB02500C05759 /* JSOffscreenCanvas.h in Headers */, 30643 30649 3140C5271FDF558200D2A873 /* JSOffscreenCanvasRenderingContext2D.h in Headers */, -
trunk/Source/WebCore/css/ElementRuleCollector.cpp
r251690 r252208 160 160 } 161 161 162 163 Vector<MatchedProperties>& ElementRuleCollector::declarationsForOrigin(MatchResult& matchResult, DeclarationOrigin declarationOrigin) 164 { 165 switch (declarationOrigin) { 166 case DeclarationOrigin::UserAgent: return matchResult.userAgentDeclarations; 167 case DeclarationOrigin::User: return matchResult.userDeclarations; 168 case DeclarationOrigin::Author: return matchResult.authorDeclarations; 169 } 170 ASSERT_NOT_REACHED(); 171 return matchResult.authorDeclarations; 172 } 173 162 174 void ElementRuleCollector::sortAndTransferMatchedRules(DeclarationOrigin declarationOrigin) 163 175 { … … 172 184 void ElementRuleCollector::transferMatchedRules(DeclarationOrigin declarationOrigin, Optional<Style::ScopeOrdinal> fromScope) 173 185 { 174 if (m_m atchedRules.size() <= m_matchedRuleTransferIndex)175 return;186 if (m_mode != SelectorChecker::Mode::CollectingRules) 187 declarationsForOrigin(m_result, declarationOrigin).reserveCapacity(m_matchedRules.size()); 176 188 177 189 for (; m_matchedRuleTransferIndex < m_matchedRules.size(); ++m_matchedRuleTransferIndex) { … … 659 671 m_result.isCacheable = computeIsCacheable(); 660 672 661 switch (declarationOrigin) { 662 case DeclarationOrigin::UserAgent: 663 m_result.userAgentDeclarations.append(WTFMove(matchedProperties)); 664 break; 665 case DeclarationOrigin::User: 666 m_result.userDeclarations.append(WTFMove(matchedProperties)); 667 break; 668 case DeclarationOrigin::Author: 669 m_result.authorDeclarations.append(WTFMove(matchedProperties)); 670 break; 671 } 673 declarationsForOrigin(m_result, declarationOrigin).append(WTFMove(matchedProperties)); 672 674 } 673 675 -
trunk/Source/WebCore/css/ElementRuleCollector.h
r251611 r252208 63 63 struct MatchResult { 64 64 bool isCacheable { true }; 65 Vector<MatchedProperties, 32> userAgentDeclarations; 66 Vector<MatchedProperties, 32> userDeclarations; 67 Vector<MatchedProperties, 32> authorDeclarations; 65 Vector<MatchedProperties> userAgentDeclarations; 66 Vector<MatchedProperties> userDeclarations; 67 Vector<MatchedProperties> authorDeclarations; 68 69 bool operator==(const MatchResult& other) const 70 { 71 return isCacheable == other.isCacheable 72 && userAgentDeclarations == other.userAgentDeclarations 73 && userDeclarations == other.userDeclarations 74 && authorDeclarations == other.authorDeclarations; 75 } 76 bool operator!=(const MatchResult& other) const { return !(*this == other); } 68 77 69 78 bool isEmpty() const { return userAgentDeclarations.isEmpty() && userDeclarations.isEmpty() && authorDeclarations.isEmpty(); } … … 123 132 124 133 enum class DeclarationOrigin { UserAgent, User, Author }; 134 static Vector<MatchedProperties>& declarationsForOrigin(MatchResult&, DeclarationOrigin); 125 135 void sortAndTransferMatchedRules(DeclarationOrigin); 126 136 void transferMatchedRules(DeclarationOrigin, Optional<Style::ScopeOrdinal> forScope = { }); -
trunk/Source/WebCore/css/RuleSet.cpp
r250817 r252208 399 399 // Add this font face to our set. 400 400 resolver->document().fontSelector().addFontFaceRule(downcast<StyleRuleFontFace>(*rule.get()), isInitiatingElementInUserAgentShadowTree); 401 resolver->invalidateMatched PropertiesCache();401 resolver->invalidateMatchedDeclarationsCache(); 402 402 } else if (is<StyleRuleKeyframes>(*rule) && resolver) 403 403 resolver->addKeyframeStyle(downcast<StyleRuleKeyframes>(*rule)); -
trunk/Source/WebCore/css/StyleResolver.cpp
r251916 r252208 117 117 StyleResolver::StyleResolver(Document& document) 118 118 : m_ruleSets(*this) 119 , m_matchedPropertiesCacheSweepTimer(*this, &StyleResolver::sweepMatchedPropertiesCache)120 119 , m_document(document) 121 120 #if ENABLE(CSS_DEVICE_ADAPTATION) … … 195 194 m_viewportStyleResolver->clearDocument(); 196 195 #endif 197 }198 199 void StyleResolver::sweepMatchedPropertiesCache()200 {201 // Look for cache entries containing a style declaration with a single ref and remove them.202 // This may happen when an element attribute mutation causes it to generate a new inlineStyle()203 // or presentationAttributeStyle(), potentially leaving this cache with the last ref on the old one.204 auto hasOneRef = [](auto& declarations) {205 for (auto& matchedProperties : declarations) {206 if (matchedProperties.properties->hasOneRef())207 return true;208 }209 return false;210 };211 212 m_matchedPropertiesCache.removeIf([&](auto& keyValue) {213 auto& entry = keyValue.value;214 return hasOneRef(entry.userAgentDeclarations) || hasOneRef(entry.userDeclarations) || hasOneRef(entry.authorDeclarations);215 });216 217 m_matchedPropertiesCacheAdditionsSinceLastSweep = 0;218 196 } 219 197 … … 1122 1100 } 1123 1101 1124 unsigned StyleResolver::computeMatchedPropertiesHash(const MatchResult& matchResult) 1125 { 1126 return StringHasher::hashMemory(matchResult.userAgentDeclarations.data(), sizeof(MatchedProperties) * matchResult.userAgentDeclarations.size()) 1127 ^ StringHasher::hashMemory(matchResult.userDeclarations.data(), sizeof(MatchedProperties) * matchResult.userDeclarations.size()) 1128 ^ StringHasher::hashMemory(matchResult.authorDeclarations.data(), sizeof(MatchedProperties) * matchResult.authorDeclarations.size()); 1129 } 1130 1131 const StyleResolver::MatchedPropertiesCacheItem* StyleResolver::findFromMatchedPropertiesCache(unsigned hash, const MatchResult& matchResult) 1132 { 1133 ASSERT(hash); 1134 1135 MatchedPropertiesCache::iterator it = m_matchedPropertiesCache.find(hash); 1136 if (it == m_matchedPropertiesCache.end()) 1137 return nullptr; 1138 1139 auto& cacheItem = it->value; 1140 if (matchResult.userAgentDeclarations != cacheItem.userAgentDeclarations || matchResult.userDeclarations != cacheItem.userDeclarations || matchResult.authorDeclarations != cacheItem.authorDeclarations) 1141 return nullptr; 1142 1143 return &cacheItem; 1144 } 1145 1146 void StyleResolver::addToMatchedPropertiesCache(const RenderStyle* style, const RenderStyle* parentStyle, unsigned hash, const MatchResult& matchResult) 1147 { 1148 static const unsigned matchedDeclarationCacheAdditionsBetweenSweeps = 100; 1149 if (++m_matchedPropertiesCacheAdditionsSinceLastSweep >= matchedDeclarationCacheAdditionsBetweenSweeps 1150 && !m_matchedPropertiesCacheSweepTimer.isActive()) { 1151 static const Seconds matchedDeclarationCacheSweepTime { 1_min }; 1152 m_matchedPropertiesCacheSweepTimer.startOneShot(matchedDeclarationCacheSweepTime); 1153 } 1154 1155 ASSERT(hash); 1156 // Note that we don't cache the original RenderStyle instance. It may be further modified. 1157 // The RenderStyle in the cache is really just a holder for the substructures and never used as-is. 1158 MatchedPropertiesCacheItem cacheItem(matchResult, style, parentStyle); 1159 m_matchedPropertiesCache.add(hash, WTFMove(cacheItem)); 1160 } 1161 1162 void StyleResolver::invalidateMatchedPropertiesCache() 1163 { 1164 m_matchedPropertiesCache.clear(); 1165 } 1166 1167 void StyleResolver::clearCachedPropertiesAffectedByViewportUnits() 1168 { 1169 Vector<unsigned, 16> toRemove; 1170 for (auto& cacheKeyValue : m_matchedPropertiesCache) { 1171 if (cacheKeyValue.value.renderStyle->hasViewportUnits()) 1172 toRemove.append(cacheKeyValue.key); 1173 } 1174 for (auto key : toRemove) 1175 m_matchedPropertiesCache.remove(key); 1176 } 1177 1178 static bool isCacheableInMatchedPropertiesCache(const Element& element, const RenderStyle* style, const RenderStyle* parentStyle) 1179 { 1180 // FIXME: Writing mode and direction properties modify state when applying to document element by calling 1181 // Document::setWritingMode/DirectionSetOnDocumentElement. We can't skip the applying by caching. 1182 if (&element == element.document().documentElement()) 1183 return false; 1184 // content:attr() value depends on the element it is being applied to. 1185 if (style->hasAttrContent() || (style->styleType() != PseudoId::None && parentStyle->hasAttrContent())) 1186 return false; 1187 if (style->hasAppearance()) 1188 return false; 1189 if (style->zoom() != RenderStyle::initialZoom()) 1190 return false; 1191 if (style->writingMode() != RenderStyle::initialWritingMode() || style->direction() != RenderStyle::initialDirection()) 1192 return false; 1193 // The cache assumes static knowledge about which properties are inherited. 1194 if (style->hasExplicitlyInheritedProperties()) 1195 return false; 1196 return true; 1197 } 1198 1199 void StyleResolver::applyMatchedProperties(const MatchResult& matchResult, const Element& element, ShouldUseMatchedPropertiesCache shouldUseMatchedPropertiesCache) 1102 void StyleResolver::invalidateMatchedDeclarationsCache() 1103 { 1104 m_matchedDeclarationsCache.invalidate(); 1105 } 1106 1107 void StyleResolver::clearCachedDeclarationsAffectedByViewportUnits() 1108 { 1109 m_matchedDeclarationsCache.clearEntriesAffectedByViewportUnits(); 1110 } 1111 1112 void StyleResolver::applyMatchedProperties(const MatchResult& matchResult, const Element& element, UseMatchedDeclarationsCache useMatchedDeclarationsCache) 1200 1113 { 1201 1114 State& state = m_state; 1202 unsigned cacheHash = shouldUseMatchedPropertiesCache && matchResult.isCacheable ? computeMatchedPropertiesHash(matchResult) : 0;1115 unsigned cacheHash = useMatchedDeclarationsCache == UseMatchedDeclarationsCache::Yes ? Style::MatchedDeclarationsCache::computeHash(matchResult) : 0; 1203 1116 auto includedProperties = Style::PropertyCascade::IncludedProperties::All; 1204 1117 1205 const MatchedPropertiesCacheItem* cacheItem = nullptr; 1206 if (cacheHash && (cacheItem = findFromMatchedPropertiesCache(cacheHash, matchResult)) 1207 && isCacheableInMatchedPropertiesCache(element, state.style(), state.parentStyle())) { 1118 auto& style = *state.style(); 1119 auto& parentStyle = *state.parentStyle(); 1120 1121 auto* cacheEntry = m_matchedDeclarationsCache.find(cacheHash, matchResult); 1122 if (cacheEntry && Style::MatchedDeclarationsCache::isCacheable(element, style, parentStyle)) { 1208 1123 // We can build up the style by copying non-inherited properties from an earlier style object built using the same exact 1209 1124 // style declarations. We then only need to apply the inherited properties, if any, as their values can depend on the 1210 1125 // element context. This is fast and saves memory by reusing the style data structures. 1211 st ate.style()->copyNonInheritedFrom(*cacheItem->renderStyle);1212 if ( state.parentStyle()->inheritedDataShared(cacheItem->parentRenderStyle.get()) && !isAtShadowBoundary(element)) {1126 style.copyNonInheritedFrom(*cacheEntry->renderStyle); 1127 if (parentStyle.inheritedDataShared(cacheEntry->parentRenderStyle.get()) && !isAtShadowBoundary(element)) { 1213 1128 InsideLink linkStatus = state.style()->insideLink(); 1214 1129 // If the cache item parent style has identical inherited properties to the current parent style then the 1215 1130 // resulting style will be identical too. We copy the inherited properties over from the cache and are done. 1216 st ate.style()->inheritFrom(*cacheItem->renderStyle);1131 style.inheritFrom(*cacheEntry->renderStyle); 1217 1132 1218 1133 // Unfortunately the link status is treated like an inherited property. We need to explicitly restore it. 1219 st ate.style()->setInsideLink(linkStatus);1134 style.setInsideLink(linkStatus); 1220 1135 return; 1221 1136 } … … 1223 1138 } 1224 1139 1225 if (elementTypeHasAppearanceFromUAStyle( *state.element())) {1140 if (elementTypeHasAppearanceFromUAStyle(element)) { 1226 1141 // FIXME: This is such a hack. 1227 1142 // Find out if there's a -webkit-appearance property in effect from the UA sheet. … … 1240 1155 1241 1156 // If the effective zoom value changes, we can't use the matched properties cache. Start over. 1242 if (cache Item && cacheItem->renderStyle->effectiveZoom() != state.style()->effectiveZoom())1243 return applyMatchedProperties(matchResult, element, DoNotUseMatchedPropertiesCache);1157 if (cacheEntry && cacheEntry->renderStyle->effectiveZoom() != style.effectiveZoom()) 1158 return applyMatchedProperties(matchResult, element, UseMatchedDeclarationsCache::No); 1244 1159 1245 1160 // If the font changed, we can't use the matched properties cache. Start over. 1246 if (cache Item && cacheItem->renderStyle->fontDescription() != state.style()->fontDescription())1247 return applyMatchedProperties(matchResult, element, DoNotUseMatchedPropertiesCache);1161 if (cacheEntry && cacheEntry->renderStyle->fontDescription() != style.fontDescription()) 1162 return applyMatchedProperties(matchResult, element, UseMatchedDeclarationsCache::No); 1248 1163 1249 1164 builder.applyLowPriorityProperties(); … … 1252 1167 ruleSets().mutableFeatures().registerContentAttribute(contentAttribute); 1253 1168 1254 if (cache Item|| !cacheHash)1169 if (cacheEntry || !cacheHash) 1255 1170 return; 1256 if (!isCacheableInMatchedPropertiesCache(*state.element(), state.style(), state.parentStyle())) 1257 return;1258 addToMatchedPropertiesCache(state.style(), state.parentStyle(), cacheHash, matchResult);1171 1172 if (Style::MatchedDeclarationsCache::isCacheable(element, style, parentStyle)) 1173 m_matchedDeclarationsCache.add(style, parentStyle, cacheHash, matchResult); 1259 1174 } 1260 1175 -
trunk/Source/WebCore/css/StyleResolver.h
r251916 r252208 26 26 #include "ElementRuleCollector.h" 27 27 #include "InspectorCSSOMWrappers.h" 28 #include "MatchedDeclarationsCache.h" 28 29 #include "MediaQueryEvaluator.h" 29 30 #include "RenderStyle.h" 30 31 #include "RuleSet.h" 31 #include "SelectorChecker.h"32 #include <bitset>33 32 #include <memory> 34 #include <wtf/Bitmap.h>35 33 #include <wtf/HashMap.h> 36 34 #include <wtf/RefPtr.h> … … 182 180 bool usesFirstLetterRules() const { return m_ruleSets.features().usesFirstLetterRules; } 183 181 184 void invalidateMatchedPropertiesCache(); 185 186 void clearCachedPropertiesAffectedByViewportUnits(); 182 void invalidateMatchedDeclarationsCache(); 183 void clearCachedDeclarationsAffectedByViewportUnits(); 187 184 188 185 private: 189 186 void adjustRenderStyle(RenderStyle&, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle, const Element*); 190 187 void adjustRenderStyleForSiteSpecificQuirks(RenderStyle&, const Element&); 191 192 enum ShouldUseMatchedPropertiesCache { DoNotUseMatchedPropertiesCache = 0, UseMatchedPropertiesCache};193 void applyMatchedProperties(const MatchResult&, const Element&, ShouldUseMatchedPropertiesCache = UseMatchedPropertiesCache);188 189 enum class UseMatchedDeclarationsCache { Yes, No }; 190 void applyMatchedProperties(const MatchResult&, const Element&, UseMatchedDeclarationsCache = UseMatchedDeclarationsCache::Yes); 194 191 195 192 DocumentRuleSets m_ruleSets; … … 253 250 void cacheBorderAndBackground(); 254 251 255 static unsigned computeMatchedPropertiesHash(const MatchResult&);256 struct MatchedPropertiesCacheItem {257 Vector<MatchedProperties> userAgentDeclarations;258 Vector<MatchedProperties> userDeclarations;259 Vector<MatchedProperties> authorDeclarations;260 std::unique_ptr<RenderStyle> renderStyle;261 std::unique_ptr<RenderStyle> parentRenderStyle;262 263 MatchedPropertiesCacheItem(const MatchResult& matchResult, const RenderStyle* style, const RenderStyle* parentStyle)264 : renderStyle(RenderStyle::clonePtr(*style))265 , parentRenderStyle(RenderStyle::clonePtr(*parentStyle))266 {267 // Assign rather than copy-construct so we only allocate as much vector capacity as needed.268 userAgentDeclarations = matchResult.userAgentDeclarations;269 userDeclarations = matchResult.userDeclarations;270 authorDeclarations = matchResult.authorDeclarations;271 }272 MatchedPropertiesCacheItem() = default;273 };274 const MatchedPropertiesCacheItem* findFromMatchedPropertiesCache(unsigned hash, const MatchResult&);275 void addToMatchedPropertiesCache(const RenderStyle*, const RenderStyle* parentStyle, unsigned hash, const MatchResult&);276 277 // Every N additions to the matched declaration cache trigger a sweep where entries holding278 // the last reference to a style declaration are garbage collected.279 void sweepMatchedPropertiesCache();280 281 typedef HashMap<unsigned, MatchedPropertiesCacheItem> MatchedPropertiesCache;282 MatchedPropertiesCache m_matchedPropertiesCache;283 284 Timer m_matchedPropertiesCacheSweepTimer;285 286 252 MediaQueryEvaluator m_mediaQueryEvaluator; 287 253 std::unique_ptr<RenderStyle> m_rootDefaultStyle; … … 303 269 State m_state; 304 270 305 unsigned m_matchedPropertiesCacheAdditionsSinceLastSweep { 0 };271 Style::MatchedDeclarationsCache m_matchedDeclarationsCache; 306 272 307 273 bool m_matchAuthorAndUserStyles { true }; -
trunk/Source/WebCore/dom/Document.cpp
r252205 r252208 2291 2291 { 2292 2292 if (auto* resolver = styleScope().resolverIfExists()) 2293 resolver->invalidateMatched PropertiesCache();2293 resolver->invalidateMatchedDeclarationsCache(); 2294 2294 if (backForwardCacheState() != NotInBackForwardCache || !renderView()) 2295 2295 return; … … 3963 3963 return; 3964 3964 3965 styleScope().resolver().clearCached PropertiesAffectedByViewportUnits();3965 styleScope().resolver().clearCachedDeclarationsAffectedByViewportUnits(); 3966 3966 3967 3967 // FIXME: Ideally, we should save the list of elements that have viewport units and only iterate over those. -
trunk/Source/WebCore/page/Page.cpp
r252205 r252208 568 568 forEachDocument([](Document& document) { 569 569 if (StyleResolver* styleResolver = document.styleScope().resolverIfExists()) 570 styleResolver->invalidateMatched PropertiesCache();570 styleResolver->invalidateMatchedDeclarationsCache(); 571 571 document.scheduleFullStyleRebuild(); 572 572 document.styleScope().didChangeStyleSheetEnvironment(); -
trunk/Source/WebCore/style/StyleTreeResolver.cpp
r251780 r252208 218 218 // "rem" units are relative to the document element's font size so we need to recompute everything. 219 219 // In practice this is rare. 220 scope().styleResolver.invalidateMatched PropertiesCache();220 scope().styleResolver.invalidateMatchedDeclarationsCache(); 221 221 descendantsToResolve = DescendantsToResolve::All; 222 222 }
Note: See TracChangeset
for help on using the changeset viewer.