From 8d7f8c628a8eb9531d7a50916111204b0887af65 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Wed, 27 Nov 2024 17:15:49 -0800 Subject: [PATCH] Sped up SubpixelGlyph::Equal --- impeller/typographer/font_glyph_pair.h | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/impeller/typographer/font_glyph_pair.h b/impeller/typographer/font_glyph_pair.h index e3df2dae50c11..87ea16b004056 100644 --- a/impeller/typographer/font_glyph_pair.h +++ b/impeller/typographer/font_glyph_pair.h @@ -87,17 +87,20 @@ struct SubpixelGlyph { struct Equal { constexpr bool operator()(const impeller::SubpixelGlyph& lhs, const impeller::SubpixelGlyph& rhs) const { - if (!lhs.properties.has_value() && !rhs.properties.has_value()) { - return lhs.glyph.index == rhs.glyph.index && - lhs.glyph.type == rhs.glyph.type && - lhs.subpixel_offset == rhs.subpixel_offset; + // Check simple non-optionals first. + if (lhs.glyph.index != rhs.glyph.index || + lhs.glyph.type != rhs.glyph.type || + lhs.subpixel_offset != rhs.subpixel_offset || + // Mixmatch properties. + lhs.properties.has_value() != rhs.properties.has_value()) { + return false; } - return lhs.glyph.index == rhs.glyph.index && - lhs.glyph.type == rhs.glyph.type && - lhs.subpixel_offset == rhs.subpixel_offset && - lhs.properties.has_value() && rhs.properties.has_value() && - GlyphProperties::Equal{}(lhs.properties.value(), - rhs.properties.value()); + if (lhs.properties.has_value()) { + // Both have properties. + return GlyphProperties::Equal{}(lhs.properties.value(), + rhs.properties.value()); + } + return true; } }; };