From 6737c8b4c5f804e23be38212295e789ff534822b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 22 Apr 2023 15:19:40 +0100 Subject: Keep the instance unused vector sorted and binary search it --- gfx/gl/instanceVertices.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'gfx/gl') 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); } } -- cgit v1.2.3