Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1796)

Unified Diff: third_party/WebKit/Source/core/svg/SVGElement.cpp

Issue 2280923002: Reduce 'iterate self and instances' helper-count in SVGElement.cpp (Closed)
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/svg/SVGElement.cpp
diff --git a/third_party/WebKit/Source/core/svg/SVGElement.cpp b/third_party/WebKit/Source/core/svg/SVGElement.cpp
index 283f3a12db89ad40c9c4735fc5c31295adcf34d0..26e0d38ddc0333ac465aafe22444790a08bb8121 100644
--- a/third_party/WebKit/Source/core/svg/SVGElement.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGElement.cpp
@@ -237,16 +237,6 @@ void SVGElement::applyActiveWebAnimations()
svgRareData()->setWebAnimatedAttributesDirty(false);
}
-template<typename T>
-static void updateInstancesAnimatedAttributeNoInvalidate(SVGElement* element, const QualifiedName& attribute, T callback)
-{
- SVGElement::InstanceUpdateBlocker blocker(element);
- for (SVGElement* instance : SVGAnimateElement::findElementInstances(element)) {
- if (SVGAnimatedPropertyBase* animatedProperty = instance->propertyFromAttribute(attribute))
- callback(*animatedProperty);
- }
-}
-
static inline void notifyAnimValChanged(SVGElement* targetElement, const QualifiedName& attributeName)
{
targetElement->invalidateSVGAttributes();
@@ -254,21 +244,20 @@ static inline void notifyAnimValChanged(SVGElement* targetElement, const Qualifi
}
template<typename T>
-static void updateInstancesAnimatedAttribute(SVGElement* element, const QualifiedName& attribute, T callback)
+static void forSelfAndInstances(SVGElement* element, T callback)
{
SVGElement::InstanceUpdateBlocker blocker(element);
- for (SVGElement* instance : SVGAnimateElement::findElementInstances(element)) {
- if (SVGAnimatedPropertyBase* animatedProperty = instance->propertyFromAttribute(attribute)) {
- callback(*animatedProperty);
- notifyAnimValChanged(instance, attribute);
- }
- }
+ for (SVGElement* instance : SVGAnimateElement::findElementInstances(element))
+ callback(instance);
}
void SVGElement::setWebAnimatedAttribute(const QualifiedName& attribute, SVGPropertyBase* value)
{
- updateInstancesAnimatedAttribute(this, attribute, [&value](SVGAnimatedPropertyBase& animatedProperty) {
- animatedProperty.setAnimatedValue(value);
+ forSelfAndInstances(this, [&attribute, &value](SVGElement* element) {
+ if (SVGAnimatedPropertyBase* animatedProperty = element->propertyFromAttribute(attribute)) {
+ animatedProperty->setAnimatedValue(value);
+ notifyAnimValChanged(element, attribute);
+ }
});
ensureSVGRareData()->webAnimatedAttributes().add(&attribute);
}
@@ -278,8 +267,11 @@ void SVGElement::clearWebAnimatedAttributes()
if (!hasSVGRareData())
return;
for (const QualifiedName* attribute : svgRareData()->webAnimatedAttributes()) {
- updateInstancesAnimatedAttribute(this, *attribute, [](SVGAnimatedPropertyBase& animatedProperty) {
- animatedProperty.animationEnded();
+ forSelfAndInstances(this, [&attribute](SVGElement* element) {
+ if (SVGAnimatedPropertyBase* animatedProperty = element->propertyFromAttribute(*attribute)) {
+ animatedProperty->animationEnded();
+ notifyAnimValChanged(element, *attribute);
+ }
});
}
svgRareData()->webAnimatedAttributes().clear();
@@ -287,24 +279,24 @@ void SVGElement::clearWebAnimatedAttributes()
void SVGElement::setAnimatedAttribute(const QualifiedName& attribute, SVGPropertyBase* value)
{
- updateInstancesAnimatedAttributeNoInvalidate(this, attribute, [&value](SVGAnimatedPropertyBase& animatedProperty) {
- animatedProperty.setAnimatedValue(value);
+ forSelfAndInstances(this, [&attribute, &value](SVGElement* element) {
+ if (SVGAnimatedPropertyBase* animatedProperty = element->propertyFromAttribute(attribute))
+ animatedProperty->setAnimatedValue(value);
});
}
void SVGElement::invalidateAnimatedAttribute(const QualifiedName& attribute)
{
- InstanceUpdateBlocker blocker(this);
- notifyAnimValChanged(this, attribute);
-
- for (SVGElement* element : instancesForElement())
+ forSelfAndInstances(this, [&attribute](SVGElement* element) {
notifyAnimValChanged(element, attribute);
+ });
}
void SVGElement::clearAnimatedAttribute(const QualifiedName& attribute)
{
- updateInstancesAnimatedAttributeNoInvalidate(this, attribute, [](SVGAnimatedPropertyBase& animatedProperty) {
- animatedProperty.animationEnded();
+ forSelfAndInstances(this, [&attribute](SVGElement* element) {
+ if (SVGAnimatedPropertyBase* animatedProperty = element->propertyFromAttribute(attribute))
+ animatedProperty->animationEnded();
});
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698