Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@
namespace facebook::react {

bool ParagraphAttributes::operator==(const ParagraphAttributes& rhs) const {
return equals<false>(rhs);
}

bool ParagraphAttributes::equalsForTextCache(
const ParagraphAttributes& rhs) const {
return equals<true>(rhs);
}

template <bool Exact>
bool ParagraphAttributes::equals(const ParagraphAttributes& rhs) const {
const auto equal = [](Float lhs, Float rhs) {
if constexpr (Exact) {
return exactFloatEquality(lhs, rhs);
}
return floatEquality(lhs, rhs);
};

return std::tie(
maximumNumberOfLines,
ellipsizeMode,
Expand All @@ -37,8 +54,8 @@ bool ParagraphAttributes::operator==(const ParagraphAttributes& rhs) const {
rhs.lineBreak,
rhs.wordBreak,
rhs.textAlignVertical) &&
floatEquality(minimumFontSize, rhs.minimumFontSize) &&
floatEquality(minimumFontScale, rhs.minimumFontScale);
equal(minimumFontSize, rhs.minimumFontSize) &&
equal(minimumFontScale, rhs.minimumFontScale);
}

#pragma mark - DebugStringConvertible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,35 +99,48 @@ class ParagraphAttributes : public DebugStringConvertible {
std::optional<TextAlignmentVertical> textAlignVertical{};

bool operator==(const ParagraphAttributes &rhs) const;
bool equalsForTextCache(const ParagraphAttributes &rhs) const;

#pragma mark - DebugStringConvertible

#if RN_DEBUG_STRING_CONVERTIBLE
SharedDebugStringConvertibleList getDebugProps() const override;
#endif

private:
template <bool Exact>
bool equals(const ParagraphAttributes &rhs) const;
};

namespace detail {

template <typename FloatProjection>
size_t hashParagraphAttributes(const ParagraphAttributes &attributes, FloatProjection projectFloat)
{
return facebook::react::hash_combine(
attributes.maximumNumberOfLines,
attributes.ellipsizeMode,
attributes.textBreakStrategy,
attributes.textWidthMode,
attributes.adjustsFontSizeToFit,
projectFloat(attributes.minimumFontSize),
attributes.includeFontPadding,
attributes.android_hyphenationFrequency,
attributes.lineBreak,
attributes.wordBreak,
projectFloat(attributes.minimumFontScale),
attributes.textAlignVertical);
}

} // namespace detail
} // namespace facebook::react

namespace std {

template <>
struct hash<facebook::react::ParagraphAttributes> {
size_t operator()(const facebook::react::ParagraphAttributes &attributes) const
{
return facebook::react::hash_combine(
attributes.maximumNumberOfLines,
attributes.ellipsizeMode,
attributes.textBreakStrategy,
attributes.textWidthMode,
attributes.adjustsFontSizeToFit,
attributes.minimumFontSize,
attributes.includeFontPadding,
attributes.android_hyphenationFrequency,
attributes.lineBreak,
attributes.wordBreak,
attributes.minimumFontScale,
attributes.textAlignVertical);
return facebook::react::detail::hashParagraphAttributes(attributes, std::identity{});
}
};
} // namespace std
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,32 @@ void TextAttributes::apply(TextAttributes textAttributes) {
#pragma mark - Operators

bool TextAttributes::operator==(const TextAttributes& rhs) const {
return textShadowOffset == rhs.textShadowOffset && equals<false>(rhs);
}

bool TextAttributes::equalsForTextCache(const TextAttributes& rhs) const {
if (textShadowOffset.has_value() != rhs.textShadowOffset.has_value()) {
return false;
}
if (textShadowOffset &&
(!exactFloatEquality(
textShadowOffset->width, rhs.textShadowOffset->width) ||
!exactFloatEquality(
textShadowOffset->height, rhs.textShadowOffset->height))) {
return false;
}
return equals<true>(rhs);
}

template <bool Exact>
bool TextAttributes::equals(const TextAttributes& rhs) const {
const auto equal = [](Float lhs, Float rhs) {
if constexpr (Exact) {
return exactFloatEquality(lhs, rhs);
}
return floatEquality(lhs, rhs);
};

return std::tie(
foregroundColor,
backgroundColor,
Expand All @@ -150,7 +176,6 @@ bool TextAttributes::operator==(const TextAttributes& rhs) const {
textDecorationColor,
textDecorationLineType,
textDecorationStyle,
textShadowOffset,
textShadowColor,
isHighlighted,
isPressable,
Expand All @@ -176,7 +201,6 @@ bool TextAttributes::operator==(const TextAttributes& rhs) const {
rhs.textDecorationColor,
rhs.textDecorationLineType,
rhs.textDecorationStyle,
rhs.textShadowOffset,
rhs.textShadowColor,
rhs.isHighlighted,
rhs.isPressable,
Expand All @@ -185,13 +209,12 @@ bool TextAttributes::operator==(const TextAttributes& rhs) const {
rhs.role,
rhs.textTransform,
rhs.textEffects) &&
floatEquality(maxFontSizeMultiplier, rhs.maxFontSizeMultiplier) &&
floatEquality(opacity, rhs.opacity) &&
floatEquality(fontSize, rhs.fontSize) &&
floatEquality(fontSizeMultiplier, rhs.fontSizeMultiplier) &&
floatEquality(letterSpacing, rhs.letterSpacing) &&
floatEquality(lineHeight, rhs.lineHeight) &&
floatEquality(textShadowRadius, rhs.textShadowRadius);
equal(maxFontSizeMultiplier, rhs.maxFontSizeMultiplier) &&
equal(opacity, rhs.opacity) && equal(fontSize, rhs.fontSize) &&
equal(fontSizeMultiplier, rhs.fontSizeMultiplier) &&
equal(letterSpacing, rhs.letterSpacing) &&
equal(lineHeight, rhs.lineHeight) &&
equal(textShadowRadius, rhs.textShadowRadius);
}

TextAttributes TextAttributes::defaultTextAttributes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,17 @@ class TextAttributes : public DebugStringConvertible {
#pragma mark - Operators

bool operator==(const TextAttributes &rhs) const;
bool equalsForTextCache(const TextAttributes &rhs) const;

#pragma mark - DebugStringConvertible

#if RN_DEBUG_STRING_CONVERTIBLE
SharedDebugStringConvertibleList getDebugProps() const override;
#endif

private:
template <bool Exact>
bool equals(const TextAttributes &rhs) const;
};

} // namespace facebook::react
Expand Down
Loading
Loading