Просмотр исходного кода

sparse_set: ::pop_all early exit on empty sets

skypjack 1 неделя назад
Родитель
Сommit
bb6a4abd6b
1 измененных файлов с 6 добавлено и 4 удалено
  1. 6 4
      src/entt/entity/sparse_set.hpp

+ 6 - 4
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;
+                }
             }
         }