Skip to content

Commit

Permalink
Compare pointers first in CSSCustomPropertyValue::equals()
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=261057
rdar://114854431

Reviewed by Chris Dumez.

When CSSCustomPropertyValue holds a variant type that is a pointer, do pointer comparison first
before comparing values. This avoids calls to the expensive `CSSVariableData::operator==`, which
gives a measurable perf boost on some Speedometer 3 subtests with lots of custom properties.

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

Canonical link: https://commits.webkit.org/267578@main
  • Loading branch information
smfr committed Sep 2, 2023
1 parent 1dc257f commit 1f4519f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Source/WebCore/css/CSSCustomPropertyValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ bool CSSCustomPropertyValue::equals(const CSSCustomPropertyValue& other) const
return WTF::switchOn(m_value, [&](const std::monostate&) {
return true;
}, [&](const Ref<CSSVariableReferenceValue>& value) {
return value.get() == std::get<Ref<CSSVariableReferenceValue>>(other.m_value).get();
auto& otherValue = std::get<Ref<CSSVariableReferenceValue>>(other.m_value);
return value.ptr() == otherValue.ptr() || value.get() == otherValue.get();
}, [&](const CSSValueID& value) {
return value == std::get<CSSValueID>(other.m_value);
}, [&](const Ref<CSSVariableData>& value) {
return value.get() == std::get<Ref<CSSVariableData>>(other.m_value).get();
auto& otherValue = std::get<Ref<CSSVariableData>>(other.m_value);
return value.ptr() == otherValue.ptr() || value.get() == otherValue.get();
}, [&](const SyntaxValue& value) {
return value == std::get<SyntaxValue>(other.m_value);
}, [&](const SyntaxValueList& value) {
Expand Down

0 comments on commit 1f4519f

Please sign in to comment.