From 61e295340ddc966e88163460bcb5991b6ad37b3d Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 26 Sep 2025 22:24:59 +0100 Subject: [PATCH] region: avoid tons of allocations for scale() pixman_region32_rectangles returns the actual rects, so we shouldnt waste cycles when scaling em --- src/math/Region.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/math/Region.cpp b/src/math/Region.cpp index 5f9d1a6..45e8f2c 100644 --- a/src/math/Region.cpp +++ b/src/math/Region.cpp @@ -145,16 +145,14 @@ CRegion& Hyprutils::Math::CRegion::scale(const Vector2D& scale) { if (scale == Vector2D{1, 1}) return *this; - auto rects = getRects(); + int rectsNum = 0; + auto RECTSARR = pixman_region32_rectangles(&m_rRegion, &rectsNum); - clear(); - - for (auto& r : rects) { - r.x1 = std::floor(r.x1 * scale.x); - r.y1 = std::floor(r.y1 * scale.y); - r.x2 = std::ceil(r.x2 * scale.x); - r.y2 = std::ceil(r.y2 * scale.y); - add(&r); + for (int i = 0; i < rectsNum; ++i) { + RECTSARR[i].x1 = std::floor(RECTSARR[i].x1 * scale.x); + RECTSARR[i].x2 = std::ceil(RECTSARR[i].x2 * scale.x); + RECTSARR[i].y1 = std::floor(RECTSARR[i].y1 * scale.y); + RECTSARR[i].y2 = std::ceil(RECTSARR[i].y2 * scale.y); } return *this;