Sfoglia il codice sorgente

sparse_set: prevent rework errors as much as possible

Michele Caini 3 anni fa
parent
commit
ecd3b8d933
1 ha cambiato i file con 6 aggiunte e 2 eliminazioni
  1. 6 2
      src/entt/entity/sparse_set.hpp

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

@@ -189,6 +189,10 @@ class basic_sparse_set {
         return sparse[pos / traits_type::page_size][fast_mod(pos, traits_type::page_size)];
     }
 
+    [[nodiscard]] auto to_iterator(const Entity entt) const {
+        return --(end() - index(entt));
+    }
+
     [[nodiscard]] auto &assure_at_least(const Entity entt) {
         const auto pos = static_cast<size_type>(traits_type::to_entity(entt));
         const auto page = pos / traits_type::page_size;
@@ -597,7 +601,7 @@ public:
      * iterator otherwise.
      */
     [[nodiscard]] iterator find(const entity_type entt) const noexcept {
-        return contains(entt) ? --(end() - index(entt)) : end();
+        return contains(entt) ? to_iterator(entt) : end();
     }
 
     /**
@@ -741,7 +745,7 @@ public:
      * @param entt A valid identifier.
      */
     void erase(const entity_type entt) {
-        const auto it = --(end() - index(entt));
+        const auto it = to_iterator(entt);
         pop(it, it + 1u);
     }