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

storage: refine ::pop to improve perf for trivially destructible types - close #1311

skypjack 1 неделя назад
Родитель
Сommit
79188ad748
3 измененных файлов с 5 добавлено и 1 удалено
  1. 0 1
      TODO
  2. 3 0
      src/entt/entity/storage.hpp
  3. 2 0
      test/common/throwing_type.hpp

+ 0 - 1
TODO

@@ -37,6 +37,5 @@ TODO:
 * use the value type mixin more in the test suite to reduce the number of utility types
 * explore "runtime" mode for hashed string where the source is copied internally
 * swap_only/swap_and_pop/in_place_pop can (should?) accept the entity
-* we can likely improve storage::pop for trivially destructible non in_place_delete types
 * storage: shrink_to_fit does not work with reentrant destructor?
 * test trivially_destructible optimization

+ 3 - 0
src/entt/entity/storage.hpp

@@ -326,6 +326,9 @@ protected:
             if constexpr(traits_type::in_place_delete) {
                 base_type::in_place_pop(first);
                 alloc_traits::destroy(allocator, std::addressof(elem));
+            } else if constexpr(std::is_trivially_destructible_v<element_type>) {
+                elem = std::move(element_at(base_type::size() - 1u));
+                base_type::swap_and_pop(first);
             } else {
                 auto &other = element_at(base_type::size() - 1u);
                 // destroying on exit allows reentrant destructors

+ 2 - 0
test/common/throwing_type.hpp

@@ -16,6 +16,8 @@ struct throwing_type {
         }
     }
 
+    ~throwing_type() { /* make it non trivially destructible */ }
+
     throwing_type &operator=(const throwing_type &other) {
         trigger = other.trigger;
         return *this;