Changeset 106351 in webkit


Ignore:
Timestamp:
Jan 31, 2012 3:04:10 AM (12 years ago)
Author:
rolandsteiner@chromium.org
Message:

<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

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r106347 r106351  
     12012-01-31  Roland Steiner  <rolandsteiner@chromium.org>
     2
     3        <style scoped>: Improve shortcut code for cases where <style scoped> isn't used
     4        https://bugs.webkit.org/show_bug.cgi?id=77410
     5
     6        Move shortcut from setupScopingElementStack(), do it at the calling sites instead
     7        (where a larger chunk of work can be skipped).
     8
     9        Reviewed by Antti Koivisto.
     10
     11        No new tests. (refactoring)
     12
     13        * css/CSSStyleSelector.cpp:
     14        (WebCore::CSSStyleSelector::setupScopingElementStack): remove shortcut code
     15        (WebCore::CSSStyleSelector::pushParent): add shortcut code
     16        (WebCore::CSSStyleSelector::matchScopedAuthorRules): factor matching scoped rules out from matchAuthorRules
     17        (WebCore::CSSStyleSelector::matchAuthorRules): add shortcut code
     18        * css/CSSStyleSelector.h:
     19        (CSSStyleSelector): add matchScopedAuthorRules
     20
    1212012-01-31  Pavel Feldman  <pfeldman@google.com>
    222
  • trunk/Source/WebCore/css/CSSStyleSelector.cpp

    r106331 r106351  
    499499void CSSStyleSelector::setupScopingElementStack(const Element* parent)
    500500{
    501     // Shortcut: abort if <style scoped> isn't used anywhere
    502     if (m_scopedAuthorStyles.isEmpty()) {
    503         ASSERT(!m_scopingElementStackParent);
    504         ASSERT(m_scopingElementStack.isEmpty());
    505         return;
    506     }
     501    // The scoping element stack shouldn't be used if <style scoped> isn't used anywhere.
     502    ASSERT(!m_scopedAuthorStyles.isEmpty());
     503
    507504    m_scopingElementStack.shrink(0);
    508505    for (; parent; parent = parent->parentOrHostElement()) {
     
    529526
    530527#if ENABLE(STYLE_SCOPED)
     528    // Shortcut: Don't bother with the scoping element stack if <style scoped> isn't used anywhere.
     529    if (m_scopedAuthorStyles.isEmpty()) {
     530        ASSERT(!m_scopingElementStackParent);
     531        ASSERT(m_scopingElementStack.isEmpty());
     532        return;
     533    }
     534    // In some wacky cases during style resolve we may get invoked for random elements.
     535    // Recreate the whole scoping element stack in such cases.
    531536    if (!scopingElementStackIsConsistent(parentsParent)) {
    532         // In some wacky cases during style resolve we may get invoked for random elements -
    533         // recreate the scoping element stack in such cases.
    534537        setupScopingElementStack(parent);
    535538        return;
    536539    }
     540    // Otherwise just push the parent onto the stack.
    537541    RuleSet* ruleSet = scopedRuleSetForElement(parent);
    538542    if (ruleSet)
     
    825829}
    826830
    827 void CSSStyleSelector::matchAuthorRules(int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules)
    828 {
    829     m_matchedRules.clear();
    830 
    831     if (!m_element)
    832         return;
    833 
    834     // Match global author rules.
    835     collectMatchingRules(m_authorStyle.get(), firstRuleIndex, lastRuleIndex, includeEmptyRules);
    836     collectMatchingRulesForRegion(m_authorStyle.get(), firstRuleIndex, lastRuleIndex, includeEmptyRules);
    837 
     831void CSSStyleSelector::matchScopedAuthorRules(int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules)
     832{
    838833#if ENABLE(STYLE_SCOPED)
     834    if (m_scopedAuthorStyles.isEmpty())
     835        return;
     836
    839837    // Match scoped author rules by traversing the scoped element stack (rebuild it if it got inconsistent).
    840838    const Element* parent = m_element->parentOrHostElement();
     
    851849        collectMatchingRulesForRegion(ruleSet, firstRuleIndex, lastRuleIndex, includeEmptyRules);
    852850    }
     851#else
     852    UNUSED_PARAM(firstRuleIndex);
     853    UNUSED_PARAM(lastRuleIndex);
     854    UNUSED_PARAM(includeEmptyRules);
    853855#endif
     856}
     857
     858void CSSStyleSelector::matchAuthorRules(int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules)
     859{
     860    m_matchedRules.clear();
     861
     862    if (!m_element)
     863        return;
     864
     865    // Match global author rules.
     866    collectMatchingRules(m_authorStyle.get(), firstRuleIndex, lastRuleIndex, includeEmptyRules);
     867    collectMatchingRulesForRegion(m_authorStyle.get(), firstRuleIndex, lastRuleIndex, includeEmptyRules);
     868
     869    matchScopedAuthorRules(firstRuleIndex, lastRuleIndex, includeEmptyRules);
    854870
    855871    sortAndTransferMatchedRules();
  • trunk/Source/WebCore/css/CSSStyleSelector.h

    r106331 r106351  
    281281    void matchRules(RuleSet*, int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules);
    282282    void matchAuthorRules(int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules);
     283    void matchScopedAuthorRules(int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules);
    283284    void collectMatchingRules(RuleSet*, int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules);
    284285    void collectMatchingRulesForRegion(RuleSet*, int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules);
Note: See TracChangeset for help on using the changeset viewer.