1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:27:45 +00:00

LibGfx: Small improvement for DisjointRectSet::shatter

This avoids a call to clone() which would be discarded immediately.
Also, avoid essentially cloning for each hammer rectangle unless
there is actually a need for it.
This commit is contained in:
Tom 2020-08-18 16:25:58 -06:00 committed by Andreas Kling
parent 983f4f935c
commit 5cd2a37079

View file

@ -173,10 +173,13 @@ DisjointRectSet DisjointRectSet::shatter(const DisjointRectSet& hammer) const
return clone();
// TODO: This could use some optimization
auto shards = clone();
for (auto& hammer_rect : hammer.m_rects) {
auto shattered = shards.shatter(hammer_rect);
shards = move(shattered);
DisjointRectSet shards = shatter(hammer.m_rects[0]);
auto rects_count = hammer.m_rects.size();
for (size_t i = 1; i < rects_count && !shards.is_empty(); i++) {
if (hammer.m_rects[i].intersects(shards.m_rects)) {
auto shattered = shards.shatter(hammer.m_rects[i]);
shards = move(shattered);
}
}
// Since there should be no overlaps, we don't need to call shatter()
return shards;