Browse Source

view: further reduce instantiations due to filters

Michele Caini 2 years ago
parent
commit
b9c86b3f99
1 changed files with 12 additions and 11 deletions
  1. 12 11
      src/entt/entity/view.hpp

+ 12 - 11
src/entt/entity/view.hpp

@@ -26,18 +26,18 @@ template<typename... Args, typename Type, std::size_t N, std::size_t... Index>
     return std::make_tuple(static_cast<Args *>(const_cast<constness_as_t<Type, Args> *>(std::get<Index>(filter)))...);
     return std::make_tuple(static_cast<Args *>(const_cast<constness_as_t<Type, Args> *>(std::get<Index>(filter)))...);
 }
 }
 
 
-template<typename Type, std::size_t N>
-[[nodiscard]] auto all_of(const std::array<const Type *, N> &filter, const typename Type::entity_type entt) noexcept {
+template<typename Type, typename Entity>
+[[nodiscard]] auto all_of(const Type *elem, const std::size_t len, const Entity entt) noexcept {
     std::size_t pos{};
     std::size_t pos{};
-    for(; pos < N && filter[pos]->contains(entt); ++pos) {}
-    return pos == N;
+    for(; pos < len && elem[pos]->contains(entt); ++pos) {}
+    return pos == len;
 }
 }
 
 
-template<typename Type, std::size_t N>
-[[nodiscard]] auto none_of(const std::array<const Type *, N> &filter, const typename Type::entity_type entt) noexcept {
+template<typename Type, typename Entity>
+[[nodiscard]] auto none_of(const Type *elem, const std::size_t len, const Entity entt) noexcept {
     std::size_t pos{};
     std::size_t pos{};
-    for(; pos < N && !(filter[pos] && filter[pos]->contains(entt)); ++pos) {}
-    return pos == N;
+    for(; pos < len && !(elem[pos] && elem[pos]->contains(entt)); ++pos) {}
+    return pos == len;
 }
 }
 
 
 template<typename Type>
 template<typename Type>
@@ -62,7 +62,7 @@ class view_iterator final {
     using iterator_type = typename Type::const_iterator;
     using iterator_type = typename Type::const_iterator;
 
 
     [[nodiscard]] bool valid(const typename iterator_type::value_type entt) const noexcept {
     [[nodiscard]] bool valid(const typename iterator_type::value_type entt) const noexcept {
-        return ((Get != 0u) || (entt != tombstone)) && (all_of(pools, entt)) && none_of(filter, entt);
+        return ((Get != 0u) || (entt != tombstone)) && (all_of(pools.data(), Get, entt)) && none_of(filter.data(), Exclude, entt);
     }
     }
 
 
 public:
 public:
@@ -256,7 +256,7 @@ class basic_view<get_t<Get...>, exclude_t<Exclude...>> {
     template<std::size_t Curr, typename Func, std::size_t... Index>
     template<std::size_t Curr, typename Func, std::size_t... Index>
     void each(Func &func, std::index_sequence<Index...>) const {
     void each(Func &func, std::index_sequence<Index...>) const {
         for(const auto curr: std::get<Curr>(pools)->each()) {
         for(const auto curr: std::get<Curr>(pools)->each()) {
-            if(const auto entt = std::get<0>(curr); ((sizeof...(Get) != 1u) || (entt != tombstone)) && ((Curr == Index || std::get<Index>(pools)->contains(entt)) && ...) && internal::none_of(filter, entt)) {
+            if(const auto entt = std::get<0>(curr); ((sizeof...(Get) != 1u) || (entt != tombstone)) && ((Curr == Index || std::get<Index>(pools)->contains(entt)) && ...) && internal::none_of(filter.data(), filter.size(), entt)) {
                 if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::tuple<entity_type>{}, std::declval<basic_view>().get({})))>) {
                 if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::tuple<entity_type>{}, std::declval<basic_view>().get({})))>) {
                     std::apply(func, std::tuple_cat(std::make_tuple(entt), dispatch_get<Curr, Index>(curr)...));
                     std::apply(func, std::tuple_cat(std::make_tuple(entt), dispatch_get<Curr, Index>(curr)...));
                 } else {
                 } else {
@@ -477,8 +477,9 @@ public:
      */
      */
     [[nodiscard]] bool contains(const entity_type entt) const noexcept {
     [[nodiscard]] bool contains(const entity_type entt) const noexcept {
         if(view) {
         if(view) {
+            auto check = opaque_check_set();
             const auto idx = view->find(entt).index();
             const auto idx = view->find(entt).index();
-            return (!(idx < 0 || idx > view->begin(0).index())) && internal::all_of(opaque_check_set(), entt) && internal::none_of(filter, entt);
+            return (!(idx < 0 || idx > view->begin(0).index())) && internal::all_of(check.data(), check.size(), entt) && internal::none_of(filter.data(), filter.size(), entt);
         }
         }
 
 
         return false;
         return false;