Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit c684de6

Browse files
authored
Sped up SubpixelGlyph::Equal (#56851)
This allows a quick out when the simple parameters fail to be equal without even looking at optional properties. In the case where they both have properties there is now one less `has_value()`. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
1 parent 559ccd2 commit c684de6

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

impeller/typographer/font_glyph_pair.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,20 @@ struct SubpixelGlyph {
8787
struct Equal {
8888
constexpr bool operator()(const impeller::SubpixelGlyph& lhs,
8989
const impeller::SubpixelGlyph& rhs) const {
90-
if (!lhs.properties.has_value() && !rhs.properties.has_value()) {
91-
return lhs.glyph.index == rhs.glyph.index &&
92-
lhs.glyph.type == rhs.glyph.type &&
93-
lhs.subpixel_offset == rhs.subpixel_offset;
90+
// Check simple non-optionals first.
91+
if (lhs.glyph.index != rhs.glyph.index ||
92+
lhs.glyph.type != rhs.glyph.type ||
93+
lhs.subpixel_offset != rhs.subpixel_offset ||
94+
// Mixmatch properties.
95+
lhs.properties.has_value() != rhs.properties.has_value()) {
96+
return false;
9497
}
95-
return lhs.glyph.index == rhs.glyph.index &&
96-
lhs.glyph.type == rhs.glyph.type &&
97-
lhs.subpixel_offset == rhs.subpixel_offset &&
98-
lhs.properties.has_value() && rhs.properties.has_value() &&
99-
GlyphProperties::Equal{}(lhs.properties.value(),
100-
rhs.properties.value());
98+
if (lhs.properties.has_value()) {
99+
// Both have properties.
100+
return GlyphProperties::Equal{}(lhs.properties.value(),
101+
rhs.properties.value());
102+
}
103+
return true;
101104
}
102105
};
103106
};

0 commit comments

Comments
 (0)