Browse Source

slightly improved registry::replace (thanks to ColinH for pointing it out)

Michele Caini 7 years ago
parent
commit
77ea28bef2
2 changed files with 2 additions and 3 deletions
  1. 1 0
      AUTHORS
  2. 1 3
      src/entt/entity/registry.hpp

+ 1 - 0
AUTHORS

@@ -7,6 +7,7 @@ skypjack
 BenediktConze
 BenediktConze
 bjadamson
 bjadamson
 ceeac
 ceeac
+ColinH
 corystegel
 corystegel
 Croydon
 Croydon
 dbacchet
 dbacchet

+ 1 - 3
src/entt/entity/registry.hpp

@@ -98,9 +98,7 @@ class basic_registry {
         Component & replace(const Entity entt, Args &&... args) {
         Component & replace(const Entity entt, Args &&... args) {
             Component component{std::forward<Args>(args)...};
             Component component{std::forward<Args>(args)...};
             on_replace.publish(*owner, entt, component);
             on_replace.publish(*owner, entt, component);
-            auto &other = sparse_set<Entity, Component>::get(entt);
-            std::swap(other, component);
-            return other;
+            return (sparse_set<Entity, Component>::get(entt) = std::move(component));
         }
         }
     };
     };