diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-22 14:56:08 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-22 14:56:11 +0100 |
commit | 59d85f9b87fc82b52f2c7438e38768aeddc3cc87 (patch) | |
tree | 285a92b58dfde1a8bb55c5085276e26d45e80f13 /gfx/gl/instanceVertices.h | |
parent | Test instancing automatic unmap when count is called, add some nodiscard (diff) | |
download | ilt-59d85f9b87fc82b52f2c7438e38768aeddc3cc87.tar.bz2 ilt-59d85f9b87fc82b52f2c7438e38768aeddc3cc87.tar.xz ilt-59d85f9b87fc82b52f2c7438e38768aeddc3cc87.zip |
Don't fill the instances unused vector unnecessarily
Diffstat (limited to 'gfx/gl/instanceVertices.h')
-rw-r--r-- | gfx/gl/instanceVertices.h | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/gfx/gl/instanceVertices.h b/gfx/gl/instanceVertices.h index edcaef4..51bf4bc 100644 --- a/gfx/gl/instanceVertices.h +++ b/gfx/gl/instanceVertices.h @@ -132,19 +132,22 @@ protected: { // Destroy p's object at(pidx).~T(); - if (next-- > index[pidx]) { - // Remember p.index is free index now - unused.push_back(pidx); + if (--next != index[pidx]) { // Move last object into p's slot new (&at(pidx)) T {std::move(data[next])}; (data[next]).~T(); - *std::find(index.begin(), index.end(), next) = index[pidx]; - // Not strictly required, but needed for uniqueness unit test assertion - index[pidx] = static_cast<size_t>(-1); + *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(); + }) = index[pidx]; } - else { + if (pidx == index.size() - 1) { index.pop_back(); } + else { + // Remember p.index is free index now + unused.push_back(pidx); + } } void |