summaryrefslogtreecommitdiff
path: root/gfx/gl/instanceVertices.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-22 15:19:40 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-22 15:19:40 +0100
commit6737c8b4c5f804e23be38212295e789ff534822b (patch)
treea4d574d12cd81d5e33886ce7ca961f7dbe872fcf /gfx/gl/instanceVertices.h
parentDon't fill the instances unused vector unnecessarily (diff)
downloadilt-6737c8b4c5f804e23be38212295e789ff534822b.tar.bz2
ilt-6737c8b4c5f804e23be38212295e789ff534822b.tar.xz
ilt-6737c8b4c5f804e23be38212295e789ff534822b.zip
Keep the instance unused vector sorted and binary search it
Diffstat (limited to 'gfx/gl/instanceVertices.h')
-rw-r--r--gfx/gl/instanceVertices.h7
1 files changed, 3 insertions, 4 deletions
diff --git a/gfx/gl/instanceVertices.h b/gfx/gl/instanceVertices.h
index 51bf4bc..228020d 100644
--- a/gfx/gl/instanceVertices.h
+++ b/gfx/gl/instanceVertices.h
@@ -137,16 +137,15 @@ protected:
new (&at(pidx)) T {std::move(data[next])};
(data[next]).~T();
*std::find_if(index.begin(), index.end(), [this](const auto & i) {
- const auto n = &i - index.data();
- return i == next && std::find(unused.begin(), unused.end(), n) == unused.end();
+ return i == next && !std::binary_search(unused.begin(), unused.end(), &i - index.data());
}) = index[pidx];
}
if (pidx == index.size() - 1) {
index.pop_back();
}
else {
- // Remember p.index is free index now
- unused.push_back(pidx);
+ // Remember p.index is free index now, keeping it sorted
+ unused.insert(std::upper_bound(unused.begin(), unused.end(), pidx), pidx);
}
}