mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibWeb: Avoid unnecessary sorting work when getting animations
This way, the list is not re-sorted on every recursive call.
This commit is contained in:
parent
1abc91ccc6
commit
693dd7b6f6
Notes:
github-actions[bot]
2025-11-26 21:20:28 +00:00
Author: https://github.com/Psychpsyo
Commit: 693dd7b6f6
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6879
Reviewed-by: https://github.com/gmta ✅
6 changed files with 26 additions and 11 deletions
|
|
@ -72,10 +72,10 @@ WebIDL::ExceptionOr<GC::Ref<Animation>> Animatable::animate(Optional<GC::Root<JS
|
||||||
WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> Animatable::get_animations(Optional<GetAnimationsOptions> options)
|
WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> Animatable::get_animations(Optional<GetAnimationsOptions> options)
|
||||||
{
|
{
|
||||||
as<DOM::Element>(*this).document().update_style();
|
as<DOM::Element>(*this).document().update_style();
|
||||||
return get_animations_internal(options);
|
return get_animations_internal(GetAnimationsSorted::Yes, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> Animatable::get_animations_internal(Optional<GetAnimationsOptions> options)
|
WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> Animatable::get_animations_internal(GetAnimationsSorted sorted, Optional<GetAnimationsOptions> options)
|
||||||
{
|
{
|
||||||
// 1. Let object be the object on which this method was called.
|
// 1. Let object be the object on which this method was called.
|
||||||
|
|
||||||
|
|
@ -107,18 +107,20 @@ WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> Animatable::get_animations_inter
|
||||||
if (options.has_value() && options->subtree) {
|
if (options.has_value() && options->subtree) {
|
||||||
Optional<WebIDL::Exception> exception;
|
Optional<WebIDL::Exception> exception;
|
||||||
TRY(target->for_each_child_of_type_fallible<DOM::Element>([&](auto& child) -> WebIDL::ExceptionOr<IterationDecision> {
|
TRY(target->for_each_child_of_type_fallible<DOM::Element>([&](auto& child) -> WebIDL::ExceptionOr<IterationDecision> {
|
||||||
relevant_animations.extend(TRY(child.get_animations(options)));
|
relevant_animations.extend(TRY(child.get_animations_internal(GetAnimationsSorted::No, options)));
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// The returned list is sorted using the composite order described for the associated animations of effects in
|
// The returned list is sorted using the composite order described for the associated animations of effects in
|
||||||
// §5.4.2 The effect stack.
|
// §5.4.2 The effect stack.
|
||||||
quick_sort(relevant_animations, [](GC::Ref<Animation>& a, GC::Ref<Animation>& b) {
|
if (sorted == GetAnimationsSorted::Yes) {
|
||||||
auto& a_effect = as<KeyframeEffect>(*a->effect());
|
quick_sort(relevant_animations, [](GC::Ref<Animation>& a, GC::Ref<Animation>& b) {
|
||||||
auto& b_effect = as<KeyframeEffect>(*b->effect());
|
auto& a_effect = as<KeyframeEffect>(*a->effect());
|
||||||
return KeyframeEffect::composite_order(a_effect, b_effect) < 0;
|
auto& b_effect = as<KeyframeEffect>(*b->effect());
|
||||||
});
|
return KeyframeEffect::composite_order(a_effect, b_effect) < 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return relevant_animations;
|
return relevant_animations;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,14 @@ public:
|
||||||
|
|
||||||
virtual ~Animatable() = default;
|
virtual ~Animatable() = default;
|
||||||
|
|
||||||
|
enum class GetAnimationsSorted {
|
||||||
|
No,
|
||||||
|
Yes
|
||||||
|
};
|
||||||
|
|
||||||
WebIDL::ExceptionOr<GC::Ref<Animation>> animate(Optional<GC::Root<JS::Object>> keyframes, Variant<Empty, double, KeyframeAnimationOptions> options = {});
|
WebIDL::ExceptionOr<GC::Ref<Animation>> animate(Optional<GC::Root<JS::Object>> keyframes, Variant<Empty, double, KeyframeAnimationOptions> options = {});
|
||||||
WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> get_animations(Optional<GetAnimationsOptions> options = {});
|
WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> get_animations(Optional<GetAnimationsOptions> options = {});
|
||||||
WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> get_animations_internal(Optional<GetAnimationsOptions> options = {});
|
WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> get_animations_internal(GetAnimationsSorted sorted, Optional<GetAnimationsOptions> options = {});
|
||||||
|
|
||||||
void associate_with_animation(GC::Ref<Animation>);
|
void associate_with_animation(GC::Ref<Animation>);
|
||||||
void disassociate_with_animation(GC::Ref<Animation>);
|
void disassociate_with_animation(GC::Ref<Animation>);
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
#include <LibGfx/Font/Typeface.h>
|
#include <LibGfx/Font/Typeface.h>
|
||||||
#include <LibGfx/Font/WOFF/Loader.h>
|
#include <LibGfx/Font/WOFF/Loader.h>
|
||||||
#include <LibGfx/Font/WOFF2/Loader.h>
|
#include <LibGfx/Font/WOFF2/Loader.h>
|
||||||
|
#include <LibWeb/Animations/Animatable.h>
|
||||||
#include <LibWeb/Animations/AnimationEffect.h>
|
#include <LibWeb/Animations/AnimationEffect.h>
|
||||||
#include <LibWeb/Animations/DocumentTimeline.h>
|
#include <LibWeb/Animations/DocumentTimeline.h>
|
||||||
#include <LibWeb/Bindings/PrincipalHostDefined.h>
|
#include <LibWeb/Bindings/PrincipalHostDefined.h>
|
||||||
|
|
@ -2573,7 +2574,9 @@ GC::Ref<ComputedProperties> StyleComputer::compute_properties(DOM::AbstractEleme
|
||||||
// 5. Add or modify CSS-defined animations
|
// 5. Add or modify CSS-defined animations
|
||||||
process_animation_definitions(computed_style, abstract_element);
|
process_animation_definitions(computed_style, abstract_element);
|
||||||
|
|
||||||
auto animations = abstract_element.element().get_animations_internal(Animations::GetAnimationsOptions { .subtree = false });
|
auto animations = abstract_element.element().get_animations_internal(
|
||||||
|
Animations::Animatable::GetAnimationsSorted::Yes,
|
||||||
|
Animations::GetAnimationsOptions { .subtree = false });
|
||||||
if (animations.is_exception()) {
|
if (animations.is_exception()) {
|
||||||
dbgln("Error getting animations for element {}", abstract_element.debug_description());
|
dbgln("Error getting animations for element {}", abstract_element.debug_description());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -5457,6 +5457,7 @@ void Document::remove_replaced_animations()
|
||||||
|
|
||||||
WebIDL::ExceptionOr<Vector<GC::Ref<Animations::Animation>>> Document::get_animations()
|
WebIDL::ExceptionOr<Vector<GC::Ref<Animations::Animation>>> Document::get_animations()
|
||||||
{
|
{
|
||||||
|
update_style();
|
||||||
return calculate_get_animations(*this);
|
return calculate_get_animations(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibWeb/Animations/Animatable.h>
|
||||||
#include <LibWeb/Animations/Animation.h>
|
#include <LibWeb/Animations/Animation.h>
|
||||||
#include <LibWeb/DOM/Document.h>
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/DOM/Utils.h>
|
#include <LibWeb/DOM/Utils.h>
|
||||||
|
|
@ -56,7 +57,9 @@ WebIDL::ExceptionOr<Vector<GC::Ref<Animations::Animation>>> calculate_get_animat
|
||||||
// method is called.
|
// method is called.
|
||||||
Vector<GC::Ref<Animations::Animation>> relevant_animations;
|
Vector<GC::Ref<Animations::Animation>> relevant_animations;
|
||||||
TRY(self.template for_each_child_of_type_fallible<Element>([&](auto& child) -> WebIDL::ExceptionOr<IterationDecision> {
|
TRY(self.template for_each_child_of_type_fallible<Element>([&](auto& child) -> WebIDL::ExceptionOr<IterationDecision> {
|
||||||
relevant_animations.extend(TRY(child.get_animations(Animations::GetAnimationsOptions { .subtree = true })));
|
relevant_animations.extend(TRY(child.get_animations_internal(
|
||||||
|
Animations::Animatable::GetAnimationsSorted::No,
|
||||||
|
Animations::GetAnimationsOptions { .subtree = true })));
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -215,6 +215,7 @@ void ShadowRoot::for_each_active_css_style_sheet(Function<void(CSS::CSSStyleShee
|
||||||
|
|
||||||
WebIDL::ExceptionOr<Vector<GC::Ref<Animations::Animation>>> ShadowRoot::get_animations()
|
WebIDL::ExceptionOr<Vector<GC::Ref<Animations::Animation>>> ShadowRoot::get_animations()
|
||||||
{
|
{
|
||||||
|
document().update_style();
|
||||||
return calculate_get_animations(*this);
|
return calculate_get_animations(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue