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

This commit is contained in:
Michele Caini
2021-05-24 10:27:10 +02:00
parent ae11652493
commit 0fe73fb6ed
2 changed files with 12 additions and 2 deletions

View File

@@ -314,11 +314,14 @@ public:
* @return This sparse set.
*/
basic_storage & operator=(basic_storage &&other) ENTT_NOEXCEPT {
maybe_resize_packed(0u);
allocator = std::move(other.allocator);
bucket_allocator = std::move(other.bucket_allocator);
packed = std::exchange(other.packed, bucket_alloc_pointer{});
bucket = std::exchange(other.bucket, 0u);
count = std::exchange(other.count, 0u);
return *this;
}

View File

@@ -91,9 +91,16 @@ TEST(Storage, Functionalities) {
ASSERT_EQ(pool.capacity(), 0u);
(void)entt::storage<int>{std::move(pool)};
entt::storage<int> other;
entt::storage<int> other{std::move(pool)};
pool = std::move(other);
other = entt::storage<int>{};
other.emplace(entt::entity{3}, 3);
other = std::move(pool);
ASSERT_EQ(pool.capacity(), 0u);
ASSERT_EQ(other.capacity(), 0u);
}
TEST(Storage, EmptyType) {