Title: [132516] trunk/Source/WebCore
- Revision
- 132516
- Author
- an...@apple.com
- Date
- 2012-10-25 12:34:56 -0700 (Thu, 25 Oct 2012)
Log 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):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (132515 => 132516)
--- trunk/Source/WebCore/ChangeLog 2012-10-25 19:34:45 UTC (rev 132515)
+++ trunk/Source/WebCore/ChangeLog 2012-10-25 19:34:56 UTC (rev 132516)
@@ -1,3 +1,24 @@
+2012-10-25 Antti Koivisto <an...@apple.com>
+
+ 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):
+
2012-10-25 Dominic Mazzoni <dmazz...@google.com>
AX: Notification should be sent when accessibilityIsIgnored changes
Modified: trunk/Source/WebCore/css/StyleResolver.cpp (132515 => 132516)
--- trunk/Source/WebCore/css/StyleResolver.cpp 2012-10-25 19:34:45 UTC (rev 132515)
+++ trunk/Source/WebCore/css/StyleResolver.cpp 2012-10-25 19:34:56 UTC (rev 132516)
@@ -4240,6 +4240,13 @@
return m_features.attrsInRules.contains(attrname.impl());
}
+bool StyleResolver::hasSelectorForId(const AtomicString& idValue) const
+{
+ if (idValue.isEmpty())
+ return false;
+ return m_features.idsInRules.contains(idValue.impl());
+}
+
void StyleResolver::addViewportDependentMediaQueryResult(const MediaQueryExp* expr, bool result)
{
m_viewportDependentMediaQueryResults.append(adoptPtr(new MediaQueryResult(*expr, result)));
Modified: trunk/Source/WebCore/css/StyleResolver.h (132515 => 132516)
--- trunk/Source/WebCore/css/StyleResolver.h 2012-10-25 19:34:45 UTC (rev 132515)
+++ trunk/Source/WebCore/css/StyleResolver.h 2012-10-25 19:34:56 UTC (rev 132516)
@@ -218,6 +218,7 @@
static bool colorFromPrimitiveValueIsDerivedFromElement(CSSPrimitiveValue*);
Color colorFromPrimitiveValue(CSSPrimitiveValue*, bool forVisitedLink = false) const;
+ bool hasSelectorForId(const AtomicString&) const;
bool hasSelectorForAttribute(const AtomicString&) const;
CSSFontSelector* fontSelector() const { return m_fontSelector.get(); }
Modified: trunk/Source/WebCore/dom/Element.cpp (132515 => 132516)
--- trunk/Source/WebCore/dom/Element.cpp 2012-10-25 19:34:45 UTC (rev 132515)
+++ trunk/Source/WebCore/dom/Element.cpp 2012-10-25 19:34:56 UTC (rev 132516)
@@ -695,6 +695,13 @@
didModifyAttribute(name, newValue);
}
+static inline AtomicString makeIdForStyleResolution(const AtomicString& value, bool inQuirksMode)
+{
+ if (inQuirksMode)
+ return value.lower();
+ return value;
+}
+
void Element::attributeChanged(const QualifiedName& name, const AtomicString& newValue)
{
parseAttribute(Attribute(name, newValue));
@@ -702,14 +709,13 @@
document()->incDOMTreeVersion();
if (isIdAttributeName(name)) {
- if (newValue != attributeData()->idForStyleResolution()) {
- if (newValue.isNull())
- attributeData()->setIdForStyleResolution(nullAtom);
- else if (document()->inQuirksMode())
- attributeData()->setIdForStyleResolution(newValue.lower());
- else
- attributeData()->setIdForStyleResolution(newValue);
- setNeedsStyleRecalc();
+ AtomicString oldId = attributeData()->idForStyleResolution();
+ AtomicString newId = makeIdForStyleResolution(newValue, document()->inQuirksMode());
+ if (newId != oldId) {
+ attributeData()->setIdForStyleResolution(newId);
+ StyleResolver* styleResolver = document()->styleResolverIfExists();
+ if (attached() && (!styleResolver || (styleResolver->hasSelectorForId(newId) || styleResolver->hasSelectorForId(oldId))))
+ setNeedsStyleRecalc();
}
} else if (name == HTMLNames::nameAttr)
setHasName(!newValue.isNull());
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes