From f255b216a064db6183a753e76552188c04c60bcc Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Wed, 9 Jul 2025 18:57:50 +0200 Subject: [PATCH] CRegion: introduce forEachRect makes us able to directly call a function on each rect instead of using getRects() allocating a vector every single time, especially when its used in hot paths like the renderer. --- include/hyprutils/math/Region.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/hyprutils/math/Region.hpp b/include/hyprutils/math/Region.hpp index f7589f2..776a668 100644 --- a/include/hyprutils/math/Region.hpp +++ b/include/hyprutils/math/Region.hpp @@ -58,6 +58,14 @@ namespace Hyprutils { CRegion copy() const; std::vector getRects() const; + template + void forEachRect(T&& cb) const { + int rectsNum = 0; + const auto* rects = pixman_region32_rectangles(&m_rRegion, &rectsNum); + for (int i = 0; i < rectsNum; ++i) { + std::forward(cb)(rects[i]); + } + } // pixman_region32_t* pixman() {