Explorar o código

sparse_set: free memory in move assignment operator (with tests)

Michele Caini %!s(int64=4) %!d(string=hai) anos
pai
achega
ae11652493
Modificáronse 2 ficheiros con 7 adicións e 0 borrados
  1. 4 0
      src/entt/entity/sparse_set.hpp
  2. 3 0
      test/entt/entity/sparse_set.cpp

+ 4 - 0
src/entt/entity/sparse_set.hpp

@@ -336,6 +336,9 @@ public:
      * @return This sparse set.
      */
     basic_sparse_set & operator=(basic_sparse_set &&other) ENTT_NOEXCEPT {
+        maybe_resize_packed(0u);
+        maybe_release_pages();
+
         allocator = std::move(other.allocator);
         bucket_allocator = std::move(other.bucket_allocator);
         sparse = std::exchange(other.sparse, bucket_alloc_pointer{});
@@ -343,6 +346,7 @@ public:
         bucket = std::exchange(other.bucket, 0u);
         count = std::exchange(other.count, 0u);
         reserved = std::exchange(other.reserved, 0u);
+
         return *this;
     }
 

+ 3 - 0
test/entt/entity/sparse_set.cpp

@@ -67,6 +67,9 @@ TEST(SparseSet, Functionalities) {
     entt::sparse_set other{std::move(set)};
 
     set = std::move(other);
+
+    other = entt::sparse_set{};
+    other.emplace(entt::entity{3});
     other = std::move(set);
 
     ASSERT_TRUE(set.empty());