Modified: trunk/Source/WebCore/ChangeLog (106350 => 106351)
--- trunk/Source/WebCore/ChangeLog 2012-01-31 10:45:33 UTC (rev 106350)
+++ trunk/Source/WebCore/ChangeLog 2012-01-31 11:04:10 UTC (rev 106351)
@@ -1,3 +1,23 @@
+2012-01-31 Roland Steiner <[email protected]>
+
+ <style scoped>: Improve shortcut code for cases where <style scoped> isn't used
+ https://bugs.webkit.org/show_bug.cgi?id=77410
+
+ Move shortcut from setupScopingElementStack(), do it at the calling sites instead
+ (where a larger chunk of work can be skipped).
+
+ Reviewed by Antti Koivisto.
+
+ No new tests. (refactoring)
+
+ * css/CSSStyleSelector.cpp:
+ (WebCore::CSSStyleSelector::setupScopingElementStack): remove shortcut code
+ (WebCore::CSSStyleSelector::pushParent): add shortcut code
+ (WebCore::CSSStyleSelector::matchScopedAuthorRules): factor matching scoped rules out from matchAuthorRules
+ (WebCore::CSSStyleSelector::matchAuthorRules): add shortcut code
+ * css/CSSStyleSelector.h:
+ (CSSStyleSelector): add matchScopedAuthorRules
+
2012-01-31 Pavel Feldman <[email protected]>
Web Inspector: DOMDebugger.setEventListenerBreakpoint should accept regular DOM event names.
Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (106350 => 106351)
--- trunk/Source/WebCore/css/CSSStyleSelector.cpp 2012-01-31 10:45:33 UTC (rev 106350)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp 2012-01-31 11:04:10 UTC (rev 106351)
@@ -498,12 +498,9 @@
#if ENABLE(STYLE_SCOPED)
void CSSStyleSelector::setupScopingElementStack(const Element* parent)
{
- // Shortcut: abort if <style scoped> isn't used anywhere
- if (m_scopedAuthorStyles.isEmpty()) {
- ASSERT(!m_scopingElementStackParent);
- ASSERT(m_scopingElementStack.isEmpty());
- return;
- }
+ // The scoping element stack shouldn't be used if <style scoped> isn't used anywhere.
+ ASSERT(!m_scopedAuthorStyles.isEmpty());
+
m_scopingElementStack.shrink(0);
for (; parent; parent = parent->parentOrHostElement()) {
RuleSet* ruleSet = scopedRuleSetForElement(parent);
@@ -528,12 +525,19 @@
m_checker.pushParent(parent);
#if ENABLE(STYLE_SCOPED)
+ // Shortcut: Don't bother with the scoping element stack if <style scoped> isn't used anywhere.
+ if (m_scopedAuthorStyles.isEmpty()) {
+ ASSERT(!m_scopingElementStackParent);
+ ASSERT(m_scopingElementStack.isEmpty());
+ return;
+ }
+ // In some wacky cases during style resolve we may get invoked for random elements.
+ // Recreate the whole scoping element stack in such cases.
if (!scopingElementStackIsConsistent(parentsParent)) {
- // In some wacky cases during style resolve we may get invoked for random elements -
- // recreate the scoping element stack in such cases.
setupScopingElementStack(parent);
return;
}
+ // Otherwise just push the parent onto the stack.
RuleSet* ruleSet = scopedRuleSetForElement(parent);
if (ruleSet)
m_scopingElementStack.append(ScopeStackFrame(parent, ruleSet));
@@ -824,18 +828,12 @@
}
}
-void CSSStyleSelector::matchAuthorRules(int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules)
+void CSSStyleSelector::matchScopedAuthorRules(int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules)
{
- m_matchedRules.clear();
-
- if (!m_element)
+#if ENABLE(STYLE_SCOPED)
+ if (m_scopedAuthorStyles.isEmpty())
return;
- // Match global author rules.
- collectMatchingRules(m_authorStyle.get(), firstRuleIndex, lastRuleIndex, includeEmptyRules);
- collectMatchingRulesForRegion(m_authorStyle.get(), firstRuleIndex, lastRuleIndex, includeEmptyRules);
-
-#if ENABLE(STYLE_SCOPED)
// Match scoped author rules by traversing the scoped element stack (rebuild it if it got inconsistent).
const Element* parent = m_element->parentOrHostElement();
if (!scopingElementStackIsConsistent(parent))
@@ -850,8 +848,26 @@
collectMatchingRules(ruleSet, firstRuleIndex, lastRuleIndex, includeEmptyRules);
collectMatchingRulesForRegion(ruleSet, firstRuleIndex, lastRuleIndex, includeEmptyRules);
}
+#else
+ UNUSED_PARAM(firstRuleIndex);
+ UNUSED_PARAM(lastRuleIndex);
+ UNUSED_PARAM(includeEmptyRules);
#endif
+}
+void CSSStyleSelector::matchAuthorRules(int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules)
+{
+ m_matchedRules.clear();
+
+ if (!m_element)
+ return;
+
+ // Match global author rules.
+ collectMatchingRules(m_authorStyle.get(), firstRuleIndex, lastRuleIndex, includeEmptyRules);
+ collectMatchingRulesForRegion(m_authorStyle.get(), firstRuleIndex, lastRuleIndex, includeEmptyRules);
+
+ matchScopedAuthorRules(firstRuleIndex, lastRuleIndex, includeEmptyRules);
+
sortAndTransferMatchedRules();
}
Modified: trunk/Source/WebCore/css/CSSStyleSelector.h (106350 => 106351)
--- trunk/Source/WebCore/css/CSSStyleSelector.h 2012-01-31 10:45:33 UTC (rev 106350)
+++ trunk/Source/WebCore/css/CSSStyleSelector.h 2012-01-31 11:04:10 UTC (rev 106351)
@@ -280,6 +280,7 @@
void matchUARules(MatchResult&);
void matchRules(RuleSet*, int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules);
void matchAuthorRules(int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules);
+ void matchScopedAuthorRules(int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules);
void collectMatchingRules(RuleSet*, int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules);
void collectMatchingRulesForRegion(RuleSet*, int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules);
void collectMatchingRulesForList(const Vector<RuleData>*, int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules);