Performance improvement for Path::GetMinMaxCoveragePoints (#37827)
This method was visible in profiles.
diff --git a/impeller/geometry/path.cc b/impeller/geometry/path.cc
index 6b2ecf8..68115f0 100644
--- a/impeller/geometry/path.cc
+++ b/impeller/geometry/path.cc
@@ -299,33 +299,37 @@
std::optional<Point> min, max;
- auto clamp = [&min, &max](const std::vector<Point>& extrema) {
- for (const auto& extremum : extrema) {
- if (!min.has_value()) {
- min = extremum;
- }
+ auto clamp = [&min, &max](const Point& point) {
+ if (min.has_value()) {
+ min->x = std::min(min->x, point.x);
+ min->y = std::min(min->y, point.y);
+ } else {
+ min = point;
+ }
- if (!max.has_value()) {
- max = extremum;
- }
-
- min->x = std::min(min->x, extremum.x);
- min->y = std::min(min->y, extremum.y);
- max->x = std::max(max->x, extremum.x);
- max->y = std::max(max->y, extremum.y);
+ if (max.has_value()) {
+ max->x = std::max(max->x, point.x);
+ max->y = std::max(max->y, point.y);
+ } else {
+ max = point;
}
};
for (const auto& linear : linears_) {
- clamp(linear.Extrema());
+ clamp(linear.p1);
+ clamp(linear.p2);
}
for (const auto& quad : quads_) {
- clamp(quad.Extrema());
+ for (const Point& point : quad.Extrema()) {
+ clamp(point);
+ }
}
for (const auto& cubic : cubics_) {
- clamp(cubic.Extrema());
+ for (const Point& point : cubic.Extrema()) {
+ clamp(point);
+ }
}
if (!min.has_value() || !max.has_value()) {