diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-22 15:19:40 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-22 15:19:40 +0100 |
commit | 6737c8b4c5f804e23be38212295e789ff534822b (patch) | |
tree | a4d574d12cd81d5e33886ce7ca961f7dbe872fcf /gfx | |
parent | Don't fill the instances unused vector unnecessarily (diff) | |
download | ilt-6737c8b4c5f804e23be38212295e789ff534822b.tar.bz2 ilt-6737c8b4c5f804e23be38212295e789ff534822b.tar.xz ilt-6737c8b4c5f804e23be38212295e789ff534822b.zip |
Keep the instance unused vector sorted and binary search it
Diffstat (limited to 'gfx')
-rw-r--r-- | gfx/gl/instanceVertices.h | 7 |
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); } } |