Performance improvement for Path::GetMinMaxCoveragePoints (flutter/engine#37827)
This method was visible in profiles.
This commit is contained in:
@@ -299,33 +299,37 @@ std::optional<std::pair<Point, Point>> Path::GetMinMaxCoveragePoints() const {
|
||||
|
||||
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()) {
|
||||
|
||||
Reference in New Issue
Block a user