runtime_view: removed an useless check, slightly improved performance
This commit is contained in:
@@ -23,8 +23,7 @@ namespace internal {
|
||||
template<typename Type>
|
||||
class runtime_view_iterator final {
|
||||
[[nodiscard]] bool valid() const {
|
||||
return (no_tombstone_check || (*it != tombstone))
|
||||
&& std::all_of(pools->begin()++, pools->end(), [entt = *it](const auto *curr) { return curr->contains(entt); })
|
||||
return 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); });
|
||||
}
|
||||
|
||||
@@ -41,8 +40,7 @@ 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},
|
||||
no_tombstone_check{std::all_of(pools->cbegin(), pools->cend(), [](const Type *cpool) { return (cpool->policy() == deletion_policy::swap_and_pop); })} {
|
||||
it{curr} {
|
||||
if(it != (*pools)[0]->end() && !valid()) {
|
||||
++(*this);
|
||||
}
|
||||
@@ -88,7 +86,6 @@ private:
|
||||
const std::vector<const Type *> *pools;
|
||||
const std::vector<const Type *> *filter;
|
||||
iterator_type it;
|
||||
bool no_tombstone_check;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
@@ -274,3 +274,40 @@ TEST(RuntimeView, StableType) {
|
||||
|
||||
ASSERT_EQ(view.size_hint(), 1u);
|
||||
}
|
||||
|
||||
TEST(RuntimeView, StableTypeWithExcludedComponent) {
|
||||
entt::registry registry;
|
||||
|
||||
const auto entity = registry.create();
|
||||
const auto other = registry.create();
|
||||
|
||||
registry.emplace<stable_type>(entity, 0);
|
||||
registry.emplace<stable_type>(other, 42);
|
||||
registry.emplace<int>(entity);
|
||||
|
||||
entt::id_type components[] = {entt::type_hash<stable_type>::value()};
|
||||
entt::id_type filter[] = {entt::type_hash<int>::value()};
|
||||
auto view = registry.runtime_view(std::begin(components), std::end(components), std::begin(filter), std::end(filter));
|
||||
|
||||
ASSERT_EQ(view.size_hint(), 2u);
|
||||
ASSERT_FALSE(view.contains(entity));
|
||||
ASSERT_TRUE(view.contains(other));
|
||||
|
||||
registry.destroy(entity);
|
||||
|
||||
ASSERT_EQ(view.size_hint(), 2u);
|
||||
ASSERT_FALSE(view.contains(entity));
|
||||
ASSERT_TRUE(view.contains(other));
|
||||
|
||||
for(auto entt: view) {
|
||||
constexpr entt::entity tombstone = entt::tombstone;
|
||||
ASSERT_NE(entt, tombstone);
|
||||
ASSERT_EQ(entt, other);
|
||||
}
|
||||
|
||||
view.each([other](const auto entt) {
|
||||
constexpr entt::entity tombstone = entt::tombstone;
|
||||
ASSERT_NE(entt, tombstone);
|
||||
ASSERT_EQ(entt, other);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user