Преглед изворни кода

sparse_set: sparse_set_iterator::data function

Michele Caini пре 3 година
родитељ
комит
3cea845a0f
3 измењених фајлова са 12 додато и 0 уклоњено
  1. 1 0
      TODO
  2. 4 0
      src/entt/entity/sparse_set.hpp
  3. 7 0
      test/entt/entity/sparse_set.cpp

+ 1 - 0
TODO

@@ -14,6 +14,7 @@ DOC:
 TODO (high prio):
 * check natvis files (periodically :)
 * remove the static storage from the const assure in the registry
+* use sparse set iterator ::data to optimize range functionalities in the registry (exploit the zero-check model)
 
 WIP:
 * get rid of observers, storage based views made them pointless - document alternatives

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

@@ -88,6 +88,10 @@ struct sparse_set_iterator final {
         return *operator->();
     }
 
+    [[nodiscard]] constexpr pointer data() const noexcept {
+        return packed ? packed->data() : nullptr;
+    }
+
     [[nodiscard]] constexpr difference_type index() const noexcept {
         return offset - 1;
     }

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

@@ -927,9 +927,16 @@ TEST(SparseSet, Iterator) {
 
     iterator end{set.begin()};
     iterator begin{};
+
+    ASSERT_EQ(end.data(), set.data());
+    ASSERT_EQ(begin.data(), nullptr);
+
     begin = set.end();
     std::swap(begin, end);
 
+    ASSERT_EQ(end.data(), set.data());
+    ASSERT_EQ(begin.data(), set.data());
+
     ASSERT_EQ(begin, set.cbegin());
     ASSERT_EQ(end, set.cend());
     ASSERT_NE(begin, end);