From 61b2bae7b72a04ff4b5b0ac20e5d0e2fbd43e519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 2 Dec 2024 02:47:01 +0200 Subject: [PATCH] Use sfl::small_vector for litter removal, avoid 99% of heap allocations --- src/openrct2/entity/Litter.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/openrct2/entity/Litter.cpp b/src/openrct2/entity/Litter.cpp index 34d3f4b7d3..12177c7516 100644 --- a/src/openrct2/entity/Litter.cpp +++ b/src/openrct2/entity/Litter.cpp @@ -13,6 +13,8 @@ #include "EntityList.h" #include "EntityRegistry.h" +#include + using namespace OpenRCT2; template<> @@ -101,7 +103,9 @@ void Litter::Create(const CoordsXYZD& litterPos, Type type) */ void Litter::RemoveAt(const CoordsXYZ& litterPos) { - std::vector 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 removals; for (auto litter : EntityTileList(litterPos)) { if (abs(litter->z - litterPos.z) <= 16)