Skip to content

Commit

Permalink
Reduce use of downcast<>() in StyleProperties
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=270758

Reviewed by Anne van Kesteren.

Reduce use of downcast<>() in StyleProperties, for performance.

* Source/WebCore/css/StyleProperties.cpp:
(WebCore::StyleProperties::immutableCopyIfNeeded const):
* Source/WebCore/css/StylePropertiesInlines.h:
(WebCore::StyleProperties::propertyAt const):
(WebCore::StyleProperties::propertyCount const):
(WebCore::StyleProperties::findPropertyIndex const):
(WebCore::StyleProperties::findCustomPropertyIndex const):

Canonical link: https://commits.webkit.org/275896@main
  • Loading branch information
cdumez committed Mar 10, 2024
1 parent 209761a commit 348b9cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Source/WebCore/css/StyleProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ constexpr unsigned maxShorthandsForLonghand = 4; // FIXME: Generate this from CS

Ref<ImmutableStyleProperties> StyleProperties::immutableCopyIfNeeded() const
{
if (auto* immutableProperties = dynamicDowncast<ImmutableStyleProperties>(*this))
return const_cast<ImmutableStyleProperties&>(*immutableProperties);
return downcast<MutableStyleProperties>(*this).immutableDeduplicatedCopy();
if (m_isMutable)
return uncheckedDowncast<MutableStyleProperties>(*this).immutableDeduplicatedCopy();
return const_cast<ImmutableStyleProperties&>(uncheckedDowncast<ImmutableStyleProperties>(*this));
}

String serializeLonghandValue(CSSPropertyID property, const CSSValue& value)
Expand Down
24 changes: 12 additions & 12 deletions Source/WebCore/css/StylePropertiesInlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ inline StyleProperties::StyleProperties(CSSParserMode mode, unsigned immutableAr

inline StyleProperties::PropertyReference StyleProperties::propertyAt(unsigned index) const
{
if (auto* mutableProperties = dynamicDowncast<MutableStyleProperties>(*this))
return mutableProperties->propertyAt(index);
return downcast<ImmutableStyleProperties>(*this).propertyAt(index);
if (m_isMutable)
return uncheckedDowncast<MutableStyleProperties>(*this).propertyAt(index);
return uncheckedDowncast<ImmutableStyleProperties>(*this).propertyAt(index);
}

inline unsigned StyleProperties::propertyCount() const
{
if (auto* mutableProperties = dynamicDowncast<MutableStyleProperties>(*this))
return mutableProperties->propertyCount();
return downcast<ImmutableStyleProperties>(*this).propertyCount();
if (m_isMutable)
return uncheckedDowncast<MutableStyleProperties>(*this).propertyCount();
return uncheckedDowncast<ImmutableStyleProperties>(*this).propertyCount();
}

inline void StyleProperties::deref() const
Expand All @@ -72,16 +72,16 @@ inline void StyleProperties::deref() const

inline int StyleProperties::findPropertyIndex(CSSPropertyID propertyID) const
{
if (auto* mutableProperties = dynamicDowncast<MutableStyleProperties>(*this))
return mutableProperties->findPropertyIndex(propertyID);
return downcast<ImmutableStyleProperties>(*this).findPropertyIndex(propertyID);
if (m_isMutable)
return uncheckedDowncast<MutableStyleProperties>(*this).findPropertyIndex(propertyID);
return uncheckedDowncast<ImmutableStyleProperties>(*this).findPropertyIndex(propertyID);
}

inline int StyleProperties::findCustomPropertyIndex(StringView propertyName) const
{
if (auto* mutableProperties = dynamicDowncast<MutableStyleProperties>(*this))
return mutableProperties->findCustomPropertyIndex(propertyName);
return downcast<ImmutableStyleProperties>(*this).findCustomPropertyIndex(propertyName);
if (m_isMutable)
return uncheckedDowncast<MutableStyleProperties>(*this).findCustomPropertyIndex(propertyName);
return uncheckedDowncast<ImmutableStyleProperties>(*this).findCustomPropertyIndex(propertyName);
}

inline bool StyleProperties::isEmpty() const
Expand Down

0 comments on commit 348b9cd

Please sign in to comment.