From 5d9c9b832685edfb0d41bd5a9af8b3eb766dc923 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Wed, 30 Nov 2022 11:55:59 -0800 Subject: [PATCH] Performance improvement for Path::GetMinMaxCoveragePoints (flutter/engine#37827) This method was visible in profiles. --- engine/src/flutter/impeller/geometry/path.cc | 36 +++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/engine/src/flutter/impeller/geometry/path.cc b/engine/src/flutter/impeller/geometry/path.cc index 6b2ecf847b..68115f0653 100644 --- a/engine/src/flutter/impeller/geometry/path.cc +++ b/engine/src/flutter/impeller/geometry/path.cc @@ -299,33 +299,37 @@ std::optional> Path::GetMinMaxCoveragePoints() const { std::optional min, max; - auto clamp = [&min, &max](const std::vector& 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()) {