Title: [289220] trunk/Source/WebCore
Revision
289220
Author
[email protected]
Date
2022-02-07 07:40:19 -0800 (Mon, 07 Feb 2022)

Log Message

Improve DocumentTimeline::animationCanBeRemoved()
https://bugs.webkit.org/show_bug.cgi?id=236230

Reviewed by Dean Jackson.

While fixing bug 236229, it appeared that DocumentTimeline::animationCanBeRemoved() could be improved while
creating the "animations" list:

- the name should make it clear that the purpose here is to create a list of animations that are protected
  since otherwise we wouldn't need that specific loop and could just run the code below directly,
- calling isRelevant() on the effect's animation is redundant since animations are guaranteed to be
  relevant if found within the effect stack,
- since we now know that we would add all animations associated with an effect in the effect stack,
  we could use Vector::map() to create the list since the lengths would match.

* animation/DocumentTimeline.cpp:
(WebCore::DocumentTimeline::animationCanBeRemoved):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (289219 => 289220)


--- trunk/Source/WebCore/ChangeLog	2022-02-07 15:30:26 UTC (rev 289219)
+++ trunk/Source/WebCore/ChangeLog	2022-02-07 15:40:19 UTC (rev 289220)
@@ -1,3 +1,23 @@
+2022-02-07  Antoine Quint  <[email protected]>
+
+        Improve DocumentTimeline::animationCanBeRemoved()
+        https://bugs.webkit.org/show_bug.cgi?id=236230
+
+        Reviewed by Dean Jackson.
+
+        While fixing bug 236229, it appeared that DocumentTimeline::animationCanBeRemoved() could be improved while
+        creating the "animations" list:
+
+        - the name should make it clear that the purpose here is to create a list of animations that are protected
+          since otherwise we wouldn't need that specific loop and could just run the code below directly,
+        - calling isRelevant() on the effect's animation is redundant since animations are guaranteed to be
+          relevant if found within the effect stack,
+        - since we now know that we would add all animations associated with an effect in the effect stack,
+          we could use Vector::map() to create the list since the lengths would match. 
+
+        * animation/DocumentTimeline.cpp:
+        (WebCore::DocumentTimeline::animationCanBeRemoved):
+
 2022-02-07  Martin Robinson  <[email protected]>
 
         Fix some compilation warnings coming from unhandled execution paths for unexpected enum values

Modified: trunk/Source/WebCore/animation/DocumentTimeline.cpp (289219 => 289220)


--- trunk/Source/WebCore/animation/DocumentTimeline.cpp	2022-02-07 15:30:26 UTC (rev 289219)
+++ trunk/Source/WebCore/animation/DocumentTimeline.cpp	2022-02-07 15:40:19 UTC (rev 289220)
@@ -242,15 +242,16 @@
     for (auto cssProperty : keyframeEffect->animatedProperties())
         propertiesToMatch.add(CSSProperty::resolveDirectionAwareProperty(cssProperty, style.direction(), style.writingMode()));
 
-    Vector<RefPtr<WebAnimation>> animations;
-    if (auto* keyframeEffectStack = target->keyframeEffectStack()) {
-        for (auto& effect : keyframeEffectStack->sortedEffects()) {
-            if (effect->animation()->isRelevant())
-                animations.append(effect->animation());
+    auto protectedAnimations = [&]() -> Vector<RefPtr<WebAnimation>> {
+        if (auto* effectStack = target->keyframeEffectStack()) {
+            return effectStack->sortedEffects().map([](auto& effect) -> RefPtr<WebAnimation> {
+                return effect->animation();
+            });
         }
-    }
+        return { };
+    }();
 
-    for (auto& animationWithHigherCompositeOrder : makeReversedRange(animations)) {
+    for (auto& animationWithHigherCompositeOrder : makeReversedRange(protectedAnimations)) {
         if (&animation == animationWithHigherCompositeOrder)
             break;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to