scene/workspacescene: don't iterate through all child items twice

Instead, use an iterator for the second loop to pick up where the first loop stopped
This commit is contained in:
Xaver Hugl 2024-08-20 13:32:09 +02:00
parent 60e3964322
commit b8b900891b

View file

@ -154,7 +154,9 @@ Item *WorkspaceScene::overlayItem() const
static bool addCandidates(SurfaceItem *item, QList<SurfaceItem *> &candidates, ssize_t maxCount, QRegion &occluded) static bool addCandidates(SurfaceItem *item, QList<SurfaceItem *> &candidates, ssize_t maxCount, QRegion &occluded)
{ {
const QList<Item *> children = item->sortedChildItems(); const QList<Item *> children = item->sortedChildItems();
for (const auto &child : children | std::views::reverse) { auto it = children.rbegin();
for (; it != children.rend(); it++) {
Item *const child = *it;
if (child->z() < 0) { if (child->z() < 0) {
break; break;
} }
@ -169,10 +171,8 @@ static bool addCandidates(SurfaceItem *item, QList<SurfaceItem *> &candidates, s
} }
candidates.push_back(item); candidates.push_back(item);
occluded += item->mapToScene(item->opaque()); occluded += item->mapToScene(item->opaque());
for (const auto &child : children | std::views::reverse) { for (; it != children.rend(); it++) {
if (child->z() >= 0) { Item *const child = *it;
continue;
}
if (child->isVisible() && !occluded.contains(child->mapToScene(child->boundingRect()).toAlignedRect())) { if (child->isVisible() && !occluded.contains(child->mapToScene(child->boundingRect()).toAlignedRect())) {
if (!addCandidates(static_cast<SurfaceItem *>(child), candidates, maxCount, occluded)) { if (!addCandidates(static_cast<SurfaceItem *>(child), candidates, maxCount, occluded)) {
return false; return false;