Skip to content
Permalink
Browse files
Style sharing: Remove O(n^2) presentation attribute checks that never…
… found anything anyway.

<http://webkit.org/b/103019>

Reviewed by Ojan Vafai.

Rely on the global presentation attribute cache and remove the slow-path code that compares
the full StylePropertySets for attribute-derived style.
There are virtually no cases of logically equivalent presentation attribute styles that don't
already share the same memory address. (Zero hits on Apple and Chromium PLT content.)

* css/StyleResolver.cpp:
(WebCore::haveIdenticalStyleAffectingAttributes):
(WebCore::StyleResolver::canShareStyleWithElement):


Canonical link: https://commits.webkit.org/121203@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@135542 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Andreas Kling committed Nov 22, 2012
1 parent a7eb2e0 commit 369d730263be0694526a0ca0839401788c51d874
Showing with 19 additions and 37 deletions.
  1. +16 −0 Source/WebCore/ChangeLog
  2. +3 −37 Source/WebCore/css/StyleResolver.cpp
@@ -1,3 +1,19 @@
2012-11-22 Andreas Kling <akling@apple.com>

Style sharing: Remove O(n^2) presentation attribute checks that never found anything anyway.
<http://webkit.org/b/103019>

Reviewed by Ojan Vafai.

Rely on the global presentation attribute cache and remove the slow-path code that compares
the full StylePropertySets for attribute-derived style.
There are virtually no cases of logically equivalent presentation attribute styles that don't
already share the same memory address. (Zero hits on Apple and Chromium PLT content.)

* css/StyleResolver.cpp:
(WebCore::haveIdenticalStyleAffectingAttributes):
(WebCore::StyleResolver::canShareStyleWithElement):

2012-11-22 Pavel Feldman <pfeldman@chromium.org>

Web Inspector: evaluate on hover regressed with the editor change
@@ -1115,32 +1115,6 @@ bool StyleResolver::canShareStyleWithControl(StyledElement* element) const
return true;
}

// This function makes some assumptions that only make sense for attribute styles (we only compare CSSProperty::id() and CSSProperty::value().)
static inline bool attributeStylesEqual(const StylePropertySet* a, const StylePropertySet* b)
{
if (a == b)
return true;
if (a->propertyCount() != b->propertyCount())
return false;
unsigned propertyCount = a->propertyCount();
for (unsigned i = 0; i < propertyCount; ++i) {
StylePropertySet::PropertyReference aProperty = a->propertyAt(i);
unsigned j;
for (j = 0; j < propertyCount; ++j) {
StylePropertySet::PropertyReference bProperty = b->propertyAt(j);
if (aProperty.id() != bProperty.id())
continue;
// We could get a few more hits by comparing cssText() here, but that gets expensive quickly.
if (aProperty.value() != bProperty.value())
return false;
break;
}
if (j == propertyCount)
return false;
}
return true;
}

static inline bool elementHasDirectionAuto(Element* element)
{
// FIXME: This line is surprisingly hot, we may wish to inline hasDirectionAuto into StyleResolver.
@@ -1167,7 +1141,7 @@ static inline bool haveIdenticalStyleAffectingAttributes(StyledElement* a, Style
return false;
}

if (a->presentationAttributeStyle() && !attributeStylesEqual(a->presentationAttributeStyle(), b->presentationAttributeStyle()))
if (a->presentationAttributeStyle() != b->presentationAttributeStyle())
return false;

#if ENABLE(PROGRESS_ELEMENT)
@@ -1200,12 +1174,6 @@ bool StyleResolver::canShareStyleWithElement(StyledElement* element) const
if (element->isSVGElement() && static_cast<SVGElement*>(element)->animatedSMILStyleProperties())
return false;
#endif
if (!!element->presentationAttributeStyle() != !!m_styledElement->presentationAttributeStyle())
return false;
const StylePropertySet* additionalPresentationAttributeStyleA = element->additionalPresentationAttributeStyle();
const StylePropertySet* additionalPresentationAttributeStyleB = m_styledElement->additionalPresentationAttributeStyle();
if (!additionalPresentationAttributeStyleA != !additionalPresentationAttributeStyleB)
return false;
if (element->isLink() != m_element->isLink())
return false;
if (style->affectedByUncommonAttributeSelectors())
@@ -1220,9 +1188,10 @@ bool StyleResolver::canShareStyleWithElement(StyledElement* element) const
return false;
if (element == element->document()->cssTarget())
return false;

if (!haveIdenticalStyleAffectingAttributes(element, m_styledElement))
return false;
if (element->additionalPresentationAttributeStyle() != m_styledElement->additionalPresentationAttributeStyle())
return false;

if (element->hasID() && m_features.idsInRules.contains(element->idForStyleResolution().impl()))
return false;
@@ -1261,9 +1230,6 @@ bool StyleResolver::canShareStyleWithElement(StyledElement* element) const
if (elementHasDirectionAuto(element))
return false;

if (additionalPresentationAttributeStyleA && !attributeStylesEqual(additionalPresentationAttributeStyleA, additionalPresentationAttributeStyleB))
return false;

if (element->isLink() && m_elementLinkState != style->insideLink())
return false;

0 comments on commit 369d730

Please sign in to comment.