Parcourir la source

sparse_set/storage: swap based move assignment operator

Michele Caini il y a 1 an
Parent
commit
9f36bec353

+ 1 - 1
TODO

@@ -45,4 +45,4 @@ TODO:
 * view and view iterator specializations for multi, single and filtered elements
 * view and view iterator specializations for multi, single and filtered elements
 * organizer support to groups
 * organizer support to groups
 * meta range: move id to meta objects and return plain types (?), then remove id from meta base and meta ctor too
 * meta range: move id to meta objects and return plain types (?), then remove id from meta base and meta ctor too
-* noexcept move op for sparse set and storage
+* review all move assignment operators

+ 1 - 5
src/entt/entity/mixin.hpp

@@ -151,11 +151,7 @@ public:
      * @return This mixin.
      * @return This mixin.
      */
      */
     basic_sigh_mixin &operator=(basic_sigh_mixin &&other) noexcept(noexcept(std::declval<underlying_type>().operator=(std::move(other)))) {
     basic_sigh_mixin &operator=(basic_sigh_mixin &&other) noexcept(noexcept(std::declval<underlying_type>().operator=(std::move(other)))) {
-        owner = other.owner;
-        construction = std::move(other.construction);
-        destruction = std::move(other.destruction);
-        update = std::move(other.update);
-        underlying_type::operator=(std::move(other));
+        swap(other);
         return *this;
         return *this;
     }
     }
 
 

+ 2 - 8
src/entt/entity/sparse_set.hpp

@@ -468,15 +468,9 @@ public:
      * @param other The instance to move from.
      * @param other The instance to move from.
      * @return This sparse set.
      * @return This sparse set.
      */
      */
-    basic_sparse_set &operator=(basic_sparse_set &&other) noexcept(false) {
+    basic_sparse_set &operator=(basic_sparse_set &&other) noexcept {
         ENTT_ASSERT(alloc_traits::is_always_equal::value || get_allocator() == other.get_allocator(), "Copying a sparse set is not allowed");
         ENTT_ASSERT(alloc_traits::is_always_equal::value || get_allocator() == other.get_allocator(), "Copying a sparse set is not allowed");
-
-        release_sparse_pages();
-        sparse = std::move(other.sparse);
-        packed = std::move(other.packed);
-        info = other.info;
-        mode = other.mode;
-        head = std::exchange(other.head, policy_to_head());
+        swap(other);
         return *this;
         return *this;
     }
     }
 
 

+ 2 - 4
src/entt/entity/storage.hpp

@@ -476,11 +476,9 @@ public:
      * @param other The instance to move from.
      * @param other The instance to move from.
      * @return This storage.
      * @return This storage.
      */
      */
-    basic_storage &operator=(basic_storage &&other) noexcept(false) {
+    basic_storage &operator=(basic_storage &&other) noexcept {
         ENTT_ASSERT(alloc_traits::is_always_equal::value || get_allocator() == other.get_allocator(), "Copying a storage is not allowed");
         ENTT_ASSERT(alloc_traits::is_always_equal::value || get_allocator() == other.get_allocator(), "Copying a storage is not allowed");
-        shrink_to_size(0u);
-        payload = std::move(other.payload);
-        base_type::operator=(std::move(other));
+        swap(other);
         return *this;
         return *this;
     }
     }
 
 

+ 1 - 1
test/entt/entity/sigh_mixin.cpp

@@ -343,7 +343,7 @@ TYPED_TEST(SighMixin, Move) {
     other = std::move(pool);
     other = std::move(pool);
     test::is_initialized(pool);
     test::is_initialized(pool);
 
 
-    ASSERT_TRUE(pool.empty());
+    ASSERT_FALSE(pool.empty());
     ASSERT_FALSE(other.empty());
     ASSERT_FALSE(other.empty());
 
 
     ASSERT_EQ(other.index(entt::entity{3}), 0u);
     ASSERT_EQ(other.index(entt::entity{3}), 0u);

+ 1 - 1
test/entt/entity/sparse_set.cpp

@@ -128,7 +128,7 @@ TYPED_TEST(SparseSet, Move) {
         other = std::move(set);
         other = std::move(set);
         test::is_initialized(set);
         test::is_initialized(set);
 
 
-        ASSERT_TRUE(set.empty());
+        ASSERT_FALSE(set.empty());
         ASSERT_FALSE(other.empty());
         ASSERT_FALSE(other.empty());
 
 
         ASSERT_EQ(other.policy(), policy);
         ASSERT_EQ(other.policy(), policy);

+ 1 - 1
test/entt/entity/storage.cpp

@@ -151,7 +151,7 @@ TYPED_TEST(Storage, Move) {
     other = std::move(pool);
     other = std::move(pool);
     test::is_initialized(pool);
     test::is_initialized(pool);
 
 
-    ASSERT_TRUE(pool.empty());
+    ASSERT_FALSE(pool.empty());
     ASSERT_FALSE(other.empty());
     ASSERT_FALSE(other.empty());
 
 
     ASSERT_EQ(other.type(), entt::type_id<value_type>());
     ASSERT_EQ(other.type(), entt::type_id<value_type>());

+ 1 - 1
test/entt/entity/storage_entity.cpp

@@ -71,7 +71,7 @@ TEST(StorageEntity, Move) {
     other = std::move(pool);
     other = std::move(pool);
     test::is_initialized(pool);
     test::is_initialized(pool);
 
 
-    ASSERT_TRUE(pool.empty());
+    ASSERT_FALSE(pool.empty());
     ASSERT_FALSE(other.empty());
     ASSERT_FALSE(other.empty());
 
 
     ASSERT_EQ(other.type(), entt::type_id<void>());
     ASSERT_EQ(other.type(), entt::type_id<void>());

+ 1 - 1
test/entt/entity/storage_no_instance.cpp

@@ -116,7 +116,7 @@ TYPED_TEST(StorageNoInstance, Move) {
     other = std::move(pool);
     other = std::move(pool);
     test::is_initialized(pool);
     test::is_initialized(pool);
 
 
-    ASSERT_TRUE(pool.empty());
+    ASSERT_FALSE(pool.empty());
     ASSERT_FALSE(other.empty());
     ASSERT_FALSE(other.empty());
 
 
     ASSERT_EQ(other.type(), entt::type_id<value_type>());
     ASSERT_EQ(other.type(), entt::type_id<value_type>());