Improve use of NeverDestroyed
[WebKit-https.git] / Source / WebCore / svg / SVGAnimatedLength.cpp
index c8b33a5..25cf3f3 100644 (file)
 
 #include "SVGAnimateElementBase.h"
 #include "SVGAnimatedNumber.h"
-#include <wtf/NeverDestroyed.h>
 
 namespace WebCore {
 
 SVGAnimatedLengthAnimator::SVGAnimatedLengthAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
     : SVGAnimatedTypeAnimator(AnimatedLength, animationElement, contextElement)
-    , m_lengthMode(SVGLength::lengthModeForAnimatedLengthAttribute(animationElement->attributeName()))
+    , m_lengthMode(SVGLengthValue::lengthModeForAnimatedLengthAttribute(animationElement->attributeName()))
 {
 }
 
-static inline SVGLength& sharedSVGLength(SVGLengthMode mode, const String& valueAsString)
-{
-    static NeverDestroyed<SVGLength> sharedLength;
-    sharedLength.get().setValueAsString(valueAsString, mode, ASSERT_NO_EXCEPTION);
-    return sharedLength;
-}
-
 std::unique_ptr<SVGAnimatedType> SVGAnimatedLengthAnimator::constructFromString(const String& string)
 {
-    return SVGAnimatedType::createLength(std::make_unique<SVGLength>(m_lengthMode, string));
+    return SVGAnimatedType::createLength(std::make_unique<SVGLengthValue>(m_lengthMode, string));
 }
 
 std::unique_ptr<SVGAnimatedType> SVGAnimatedLengthAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
@@ -54,7 +46,7 @@ void SVGAnimatedLengthAnimator::stopAnimValAnimation(const SVGElementAnimatedPro
     stopAnimValAnimationForType<SVGAnimatedLength>(animatedTypes);
 }
 
-void SVGAnimatedLengthAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType* type)
+void SVGAnimatedLengthAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType& type)
 {
     resetFromBaseValue<SVGAnimatedLength>(animatedTypes, type, &SVGAnimatedType::length);
 }
@@ -75,15 +67,17 @@ void SVGAnimatedLengthAnimator::addAnimatedTypes(SVGAnimatedType* from, SVGAnima
     ASSERT(from->type() == to->type());
 
     SVGLengthContext lengthContext(m_contextElement);
-    const SVGLength& fromLength = from->length();
-    SVGLength& toLength = to->length();
+    const auto& fromLength = from->length();
+    auto& toLength = to->length();
 
-    toLength.setValue(toLength.value(lengthContext) + fromLength.value(lengthContext), lengthContext, ASSERT_NO_EXCEPTION);
+    toLength.setValue(toLength.value(lengthContext) + fromLength.value(lengthContext), lengthContext);
 }
 
-static SVGLength parseLengthFromString(SVGAnimationElement* animationElement, const String& string)
+static SVGLengthValue parseLengthFromString(SVGAnimationElement* animationElement, const String& string)
 {
-    return sharedSVGLength(SVGLength::lengthModeForAnimatedLengthAttribute(animationElement->attributeName()), string);
+    SVGLengthValue length;
+    length.setValueAsString(string, SVGLengthValue::lengthModeForAnimatedLengthAttribute(animationElement->attributeName()));
+    return length;
 }
 
 void SVGAnimatedLengthAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType* toAtEndOfDuration, SVGAnimatedType* animated)
@@ -91,30 +85,30 @@ void SVGAnimatedLengthAnimator::calculateAnimatedValue(float percentage, unsigne
     ASSERT(m_animationElement);
     ASSERT(m_contextElement);
 
-    SVGLength fromSVGLength = m_animationElement->animationMode() == ToAnimation ? animated->length() : from->length();
-    SVGLength toSVGLength = to->length();
-    const SVGLength& toAtEndOfDurationSVGLength = toAtEndOfDuration->length();
-    SVGLength& animatedSVGLength = animated->length();
+    auto fromSVGLength = m_animationElement->animationMode() == ToAnimation ? animated->length() : from->length();
+    auto toSVGLength = to->length();
+    const auto& toAtEndOfDurationSVGLength = toAtEndOfDuration->length();
+    auto& animatedSVGLength = animated->length();
 
     // Apply CSS inheritance rules.
-    m_animationElement->adjustForInheritance<SVGLength>(parseLengthFromString, m_animationElement->fromPropertyValueType(), fromSVGLength, m_contextElement);
-    m_animationElement->adjustForInheritance<SVGLength>(parseLengthFromString, m_animationElement->toPropertyValueType(), toSVGLength, m_contextElement);
+    m_animationElement->adjustForInheritance<SVGLengthValue>(parseLengthFromString, m_animationElement->fromPropertyValueType(), fromSVGLength, m_contextElement);
+    m_animationElement->adjustForInheritance<SVGLengthValue>(parseLengthFromString, m_animationElement->toPropertyValueType(), toSVGLength, m_contextElement);
 
     SVGLengthContext lengthContext(m_contextElement);
     float animatedNumber = animatedSVGLength.value(lengthContext);
     SVGLengthType unitType = percentage < 0.5 ? fromSVGLength.unitType() : toSVGLength.unitType();
     m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromSVGLength.value(lengthContext), toSVGLength.value(lengthContext), toAtEndOfDurationSVGLength.value(lengthContext), animatedNumber);
 
-    animatedSVGLength.setValue(lengthContext, animatedNumber, m_lengthMode, unitType, ASSERT_NO_EXCEPTION);
+    animatedSVGLength.setValue(lengthContext, animatedNumber, m_lengthMode, unitType);
 }
 
 float SVGAnimatedLengthAnimator::calculateDistance(const String& fromString, const String& toString)
 {
     ASSERT(m_animationElement);
     ASSERT(m_contextElement);
-    SVGLengthMode lengthMode = SVGLength::lengthModeForAnimatedLengthAttribute(m_animationElement->attributeName());
-    SVGLength from = SVGLength(lengthMode, fromString);
-    SVGLength to = SVGLength(lengthMode, toString);
+    auto lengthMode = SVGLengthValue::lengthModeForAnimatedLengthAttribute(m_animationElement->attributeName());
+    auto from = SVGLengthValue(lengthMode, fromString);
+    auto to = SVGLengthValue(lengthMode, toString);
     SVGLengthContext lengthContext(m_contextElement);
     return fabsf(to.value(lengthContext) - from.value(lengthContext));
 }