Skip to content

Commit

Permalink
Avoid traversing all custom properties in Styleable::updateCSSTransit…
Browse files Browse the repository at this point in the history
…ions when not needed

https://bugs.webkit.org/show_bug.cgi?id=267536
rdar://121002539

Reviewed by Antoine Quint.

* Source/WebCore/css/CSSCustomPropertyValue.cpp:
(WebCore::CSSCustomPropertyValue::isAnimatable const):

Factor into a function.

* Source/WebCore/css/CSSCustomPropertyValue.h:
* Source/WebCore/rendering/style/StyleCustomPropertyData.cpp:
(WebCore::StyleCustomPropertyData::StyleCustomPropertyData):
(WebCore::StyleCustomPropertyData::set):

Check if the newly set property is animatable.

(WebCore::StyleCustomPropertyData::size const): Deleted.
* Source/WebCore/rendering/style/StyleCustomPropertyData.h:
(WebCore::StyleCustomPropertyData::size const):
(WebCore::StyleCustomPropertyData::mayHaveAnimatableProperties const):
* Source/WebCore/style/Styleable.cpp:
(WebCore::Styleable::updateCSSTransitions const):

Bail out if before traversing if we already know the properties are not animatable.

Canonical link: https://commits.webkit.org/273045@main
  • Loading branch information
anttijk committed Jan 15, 2024
1 parent 0f1b1ef commit 04dd4ec
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Source/WebCore/css/CSSCustomPropertyValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,9 @@ bool CSSCustomPropertyValue::isCurrentColor() const
return token.id() == CSSValueCurrentcolor;
}

bool CSSCustomPropertyValue::isAnimatable() const
{
return std::holds_alternative<SyntaxValue>(m_value) || std::holds_alternative<SyntaxValueList>(m_value);
}

}
1 change: 1 addition & 0 deletions Source/WebCore/css/CSSCustomPropertyValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class CSSCustomPropertyValue final : public CSSValue {
bool isInherit() const { return std::holds_alternative<CSSValueID>(m_value) && std::get<CSSValueID>(m_value) == CSSValueInherit; }
bool isCurrentColor() const;
bool containsCSSWideKeyword() const;
bool isAnimatable() const;

const VariantValue& value() const { return m_value; }

Expand Down
8 changes: 3 additions & 5 deletions Source/WebCore/rendering/style/StyleCustomPropertyData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static constexpr auto maximumAncestorCount = 4;

StyleCustomPropertyData::StyleCustomPropertyData(const StyleCustomPropertyData& other)
: m_size(other.m_size)
, m_mayHaveAnimatableProperties(other.m_mayHaveAnimatableProperties)
{
auto shouldReferenceAsParentValues = [&] {
// Always reference the root style since it likely gets shared a lot.
Expand Down Expand Up @@ -81,6 +82,8 @@ void StyleCustomPropertyData::set(const AtomString& name, Ref<const CSSCustomPro
return !existing || !existing->equals(value);
}());

m_mayHaveAnimatableProperties = m_mayHaveAnimatableProperties || value->isAnimatable();

auto addResult = m_ownValues.set(name, WTFMove(value));

bool isNewProperty = addResult.isNewEntry && (!m_parentValues || !m_parentValues->get(name));
Expand Down Expand Up @@ -168,9 +171,4 @@ AtomString StyleCustomPropertyData::findKeyAtIndex(unsigned index) const
return key;
}

unsigned StyleCustomPropertyData::size() const
{
return m_size;
}

} // namespace WebCore
4 changes: 3 additions & 1 deletion Source/WebCore/rendering/style/StyleCustomPropertyData.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class StyleCustomPropertyData : public RefCounted<StyleCustomPropertyData> {
const CSSCustomPropertyValue* get(const AtomString&) const;
void set(const AtomString&, Ref<const CSSCustomPropertyValue>&&);

unsigned size() const;
unsigned size() const { return m_size; }
bool mayHaveAnimatableProperties() const { return m_mayHaveAnimatableProperties; }

void forEach(const Function<IterationStatus(const KeyValuePair<AtomString, RefPtr<const CSSCustomPropertyValue>>&)>&) const;
AtomString findKeyAtIndex(unsigned) const;
Expand All @@ -59,6 +60,7 @@ class StyleCustomPropertyData : public RefCounted<StyleCustomPropertyData> {
CustomPropertyValueMap m_ownValues;
unsigned m_size { 0 };
unsigned m_ancestorCount { 0 };
bool m_mayHaveAnimatableProperties { false };
#if ASSERT_ENABLED
mutable bool m_hasChildren { false };
#endif
Expand Down
7 changes: 4 additions & 3 deletions Source/WebCore/style/Styleable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,12 @@ void Styleable::updateCSSTransitions(const RenderStyle& currentStyle, const Rend

transitionCustomProperties.clear();
auto gatherAnimatableCustomProperties = [&](const StyleCustomPropertyData& customPropertyData) {
if (!customPropertyData.mayHaveAnimatableProperties())
return;

customPropertyData.forEach([&](auto& customPropertyAndValuePair) {
auto [customProperty, customPropertyValue] = customPropertyAndValuePair;
auto& variantValue = customPropertyValue->value();
if (std::holds_alternative<CSSCustomPropertyValue::SyntaxValue>(variantValue)
|| std::holds_alternative<CSSCustomPropertyValue::SyntaxValueList>(variantValue))
if (customPropertyValue->isAnimatable())
transitionCustomProperties.add(customProperty);
return IterationStatus::Continue;
});
Expand Down

0 comments on commit 04dd4ec

Please sign in to comment.