Browse Source

runtime_view: slightly optimized iterators

Michele Caini 4 years ago
parent
commit
c05dddc56e
1 changed files with 5 additions and 2 deletions
  1. 5 2
      src/entt/entity/runtime_view.hpp

+ 5 - 2
src/entt/entity/runtime_view.hpp

@@ -23,7 +23,8 @@ namespace internal {
 template<typename Type>
 class runtime_view_iterator final {
     [[nodiscard]] bool valid() const {
-        return std::all_of(pools->begin(), pools->end(), [entt = *it](const auto *curr) { return curr->contains(entt); })
+        return (!tombstone_check || *it != tombstone)
+               && std::all_of(++pools->begin(), pools->end(), [entt = *it](const auto *curr) { return curr->contains(entt); })
                && std::none_of(filter->cbegin(), filter->cend(), [entt = *it](const auto *curr) { return curr && curr->contains(entt); });
     }
 
@@ -40,7 +41,8 @@ public:
     runtime_view_iterator(const std::vector<const Type *> &cpools, const std::vector<const Type *> &ignore, iterator_type curr) ENTT_NOEXCEPT
         : pools{&cpools},
           filter{&ignore},
-          it{curr} {
+          it{curr},
+          tombstone_check{pools->size() == 1u && (*pools)[0u]->policy() == deletion_policy::in_place} {
         if(it != (*pools)[0]->end() && !valid()) {
             ++(*this);
         }
@@ -86,6 +88,7 @@ private:
     const std::vector<const Type *> *pools;
     const std::vector<const Type *> *filter;
     iterator_type it;
+    bool tombstone_check;
 };
 
 } // namespace internal