Changeset 132516 in webkit


Ignore:
Timestamp:
Oct 25, 2012, 12:34:56 PM (12 years ago)
Author:
Antti Koivisto
Message:

Avoid unnecessary style recalcs on id attribute mutation.
https://bugs.webkit.org/show_bug.cgi?id=100395

Reviewed by Andreas Kling.

There is no need to invalidate element style on id attribute change if neither the old nor the new id were
mentioned in any stylesheet. This is similar to the optimization we already have for class attributes.

Recalculating element style is expensive. It seems id attribute mutation is often used in scripts for purposes other than styling.

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::hasSelectorForId):
(WebCore):

  • css/StyleResolver.h:
  • dom/Element.cpp:

(WebCore::makeIdForStyleResolution):
(WebCore):
(WebCore::Element::attributeChanged):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r132514 r132516  
     12012-10-25  Antti Koivisto  <antti@apple.com>
     2
     3        Avoid unnecessary style recalcs on id attribute mutation.
     4        https://bugs.webkit.org/show_bug.cgi?id=100395
     5
     6        Reviewed by Andreas Kling.
     7
     8        There is no need to invalidate element style on id attribute change if neither the old nor the new id were
     9        mentioned in any stylesheet. This is similar to the optimization we already have for class attributes.
     10       
     11        Recalculating element style is expensive. It seems id attribute mutation is often used in scripts for purposes other than styling.
     12
     13        * css/StyleResolver.cpp:
     14        (WebCore::StyleResolver::hasSelectorForId):
     15        (WebCore):
     16        * css/StyleResolver.h:
     17        * dom/Element.cpp:
     18        (WebCore::makeIdForStyleResolution):
     19        (WebCore):
     20        (WebCore::Element::attributeChanged):
     21
    1222012-10-25  Dominic Mazzoni  <dmazzoni@google.com>
    223
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r132416 r132516  
    42414241}
    42424242
     4243bool StyleResolver::hasSelectorForId(const AtomicString& idValue) const
     4244{
     4245    if (idValue.isEmpty())
     4246        return false;
     4247    return m_features.idsInRules.contains(idValue.impl());
     4248}
     4249
    42434250void StyleResolver::addViewportDependentMediaQueryResult(const MediaQueryExp* expr, bool result)
    42444251{
  • trunk/Source/WebCore/css/StyleResolver.h

    r132403 r132516  
    219219    Color colorFromPrimitiveValue(CSSPrimitiveValue*, bool forVisitedLink = false) const;
    220220
     221    bool hasSelectorForId(const AtomicString&) const;
    221222    bool hasSelectorForAttribute(const AtomicString&) const;
    222223
  • trunk/Source/WebCore/dom/Element.cpp

    r132514 r132516  
    696696}
    697697
     698static inline AtomicString makeIdForStyleResolution(const AtomicString& value, bool inQuirksMode)
     699{
     700    if (inQuirksMode)
     701        return value.lower();
     702    return value;
     703}
     704
    698705void Element::attributeChanged(const QualifiedName& name, const AtomicString& newValue)
    699706{
     
    703710
    704711    if (isIdAttributeName(name)) {
    705         if (newValue != attributeData()->idForStyleResolution()) {
    706             if (newValue.isNull())
    707                 attributeData()->setIdForStyleResolution(nullAtom);
    708             else if (document()->inQuirksMode())
    709                 attributeData()->setIdForStyleResolution(newValue.lower());
    710             else
    711                 attributeData()->setIdForStyleResolution(newValue);
    712             setNeedsStyleRecalc();
     712        AtomicString oldId = attributeData()->idForStyleResolution();
     713        AtomicString newId = makeIdForStyleResolution(newValue, document()->inQuirksMode());
     714        if (newId != oldId) {
     715            attributeData()->setIdForStyleResolution(newId);
     716            StyleResolver* styleResolver = document()->styleResolverIfExists();
     717            if (attached() && (!styleResolver || (styleResolver->hasSelectorForId(newId) || styleResolver->hasSelectorForId(oldId))))
     718                setNeedsStyleRecalc();
    713719        }
    714720    } else if (name == HTMLNames::nameAttr)
Note: See TracChangeset for help on using the changeset viewer.