diff --git a/engine/src/flutter/impeller/typographer/font_glyph_pair.h b/engine/src/flutter/impeller/typographer/font_glyph_pair.h index 0b89c803af..16eaecdc66 100644 --- a/engine/src/flutter/impeller/typographer/font_glyph_pair.h +++ b/engine/src/flutter/impeller/typographer/font_glyph_pair.h @@ -31,8 +31,20 @@ struct FontGlyphPair { struct Hash { std::size_t operator()(const FontGlyphPair& p) const { - return fml::HashCombine(p.font.GetHash(), p.glyph.index, p.glyph.type, - p.scale); + static_assert(sizeof(p.glyph.index) == 2); + static_assert(sizeof(p.glyph.type) == 1); + size_t index = p.glyph.index; + size_t type = static_cast(p.glyph.type); + // By packaging multiple values in a single size_t the hash function is + // more efficient without losing entropy. + if (sizeof(size_t) == 8 && sizeof(Scalar) == 4) { + const float* fScale = &p.scale; + size_t nScale = *reinterpret_cast(fScale); + size_t index_type_scale = nScale << 32 | index << 16 | type; + return fml::HashCombine(p.font.GetHash(), index_type_scale); + } + size_t index_type = index << 16 | type; + return fml::HashCombine(p.font.GetHash(), index_type, p.scale); } }; struct Equal {