Changeset 153699 in webkit
- Timestamp:
- Aug 4, 2013, 8:57:13 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r153698 r153699 1 2013-08-04 Andreas Kling <akling@apple.com> 2 3 Inserting a rule into an empty style sheet shouldn't trigger style recalc unless necessary. 4 <http://webkit.org/b/119475> 5 <rdar://problem/14643481> 6 7 Reviewed by Antti Koivisto. 8 9 This is kind of a cheesy optimization, but it turns out that the use case is quite common. 10 The pattern goes like this: 11 12 (1) Create <style> element. 13 (2) Add it to the document's <head>. 14 (3) .addRule() one rule through the CSSOM API. 15 16 Prior to this patch, (3) would always cause a full (deferred) style recalc. 17 18 Now that we exclude empty style sheets from the document's (effective) active set, 19 we can piggyback on the style invalidation analysis when transitioning from an empty 20 sheet to a single-rule sheet. 21 22 In other words, add a special code path for the first rule insertion into an empty, 23 in-document style sheet to minimize the amount of invalidation that happens. 24 25 * css/CSSStyleSheet.cpp: 26 (WebCore::CSSStyleSheet::didMutateRules): 27 (WebCore::CSSStyleSheet::insertRule): 28 * css/CSSStyleSheet.h: 29 (WebCore::CSSStyleSheet::RuleMutationScope::RuleMutationScope): 30 (WebCore::CSSStyleSheet::RuleMutationScope::~RuleMutationScope): 31 1 32 2013-08-04 Claudio Saavedra <csaavedra@igalia.com> 2 33 -
trunk/Source/WebCore/css/CSSStyleSheet.cpp
r153641 r153699 148 148 } 149 149 150 void CSSStyleSheet::didMutateRules( )150 void CSSStyleSheet::didMutateRules(RuleMutationType mutationType) 151 151 { 152 152 ASSERT(m_contents->isMutable()); 153 153 ASSERT(m_contents->hasOneClient()); 154 154 155 didMutate(); 155 Document* owner = ownerDocument(); 156 if (!owner) 157 return; 158 owner->styleResolverChanged(mutationType == InsertionIntoEmptySheet ? DeferRecalcStyleIfNeeded : DeferRecalcStyle); 156 159 } 157 160 … … 276 279 return 0; 277 280 } 278 RuleMutationScope mutationScope(this); 281 282 RuleMutationType mutationType = !length() ? InsertionIntoEmptySheet : OtherMutation; 283 RuleMutationScope mutationScope(this, mutationType); 279 284 280 285 bool success = m_contents->wrapperInsertRule(rule, index); -
trunk/Source/WebCore/css/CSSStyleSheet.h
r153641 r153699 86 86 void setTitle(const String& title) { m_title = title; } 87 87 88 enum RuleMutationType { OtherMutation, InsertionIntoEmptySheet }; 89 88 90 class RuleMutationScope { 89 91 WTF_MAKE_NONCOPYABLE(RuleMutationScope); 90 92 public: 91 RuleMutationScope(CSSStyleSheet* );93 RuleMutationScope(CSSStyleSheet*, RuleMutationType = OtherMutation); 92 94 RuleMutationScope(CSSRule*); 93 95 ~RuleMutationScope(); … … 95 97 private: 96 98 CSSStyleSheet* m_styleSheet; 99 RuleMutationType m_mutationType; 97 100 }; 98 101 99 102 void willMutateRules(); 100 void didMutateRules( );103 void didMutateRules(RuleMutationType = OtherMutation); 101 104 void didMutate(); 102 105 … … 129 132 }; 130 133 131 inline CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSStyleSheet* sheet )134 inline CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSStyleSheet* sheet, RuleMutationType mutationType) 132 135 : m_styleSheet(sheet) 136 , m_mutationType(mutationType) 133 137 { 134 138 if (m_styleSheet) … … 138 142 inline CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSRule* rule) 139 143 : m_styleSheet(rule ? rule->parentStyleSheet() : 0) 144 , m_mutationType(OtherMutation) 140 145 { 141 146 if (m_styleSheet) … … 146 151 { 147 152 if (m_styleSheet) 148 m_styleSheet->didMutateRules( );153 m_styleSheet->didMutateRules(m_mutationType); 149 154 } 150 155
Note:
See TracChangeset
for help on using the changeset viewer.