1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-04 13:42:55 +01:00

Use sfl::small_vector for litter removal, avoid 99% of heap allocations

This commit is contained in:
ζeh Matt
2024-12-02 02:47:01 +02:00
parent 10544ca81b
commit 61b2bae7b7

View File

@@ -13,6 +13,8 @@
#include "EntityList.h"
#include "EntityRegistry.h"
#include <sfl/small_vector.hpp>
using namespace OpenRCT2;
template<>
@@ -101,7 +103,9 @@ void Litter::Create(const CoordsXYZD& litterPos, Type type)
*/
void Litter::RemoveAt(const CoordsXYZ& litterPos)
{
std::vector<Litter*> removals;
// There can be a lot of litter entities on the same tile, avoid heap allocations
// by having the first 512 stored in a small_vector which is on the stack.
sfl::small_vector<Litter*, 512> removals;
for (auto litter : EntityTileList<Litter>(litterPos))
{
if (abs(litter->z - litterPos.z) <= 16)