From bb6a4abd6ba021e0967669320419e79f852a418d Mon Sep 17 00:00:00 2001 From: skypjack Date: Tue, 24 Feb 2026 15:08:01 +0100 Subject: [PATCH] sparse_set: ::pop_all early exit on empty sets --- src/entt/entity/sparse_set.hpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/entt/entity/sparse_set.hpp b/src/entt/entity/sparse_set.hpp index 9f3ec0b10..2ffdf9062 100644 --- a/src/entt/entity/sparse_set.hpp +++ b/src/entt/entity/sparse_set.hpp @@ -294,10 +294,12 @@ protected: /*! @brief Erases all entities of a sparse set. */ virtual void pop_all() { - // suboptimal with few entities, but exploits cache way more with many - for (auto&& elem : sparse) { - for (size_type pos{}; pos < traits_type::page_size; ++pos) { - elem[pos] = null; + if(!packed.empty()) { + // suboptimal with few entities, but exploits cache way more with many + for(auto &&elem: sparse) { + for(size_type pos{}; pos < traits_type::page_size; ++pos) { + elem[pos] = null; + } } }