Browse Source

view: further reduce instantiations

Michele Caini 1 year ago
parent
commit
587a012ae1
2 changed files with 15 additions and 16 deletions
  1. 1 0
      TODO
  2. 14 16
      src/entt/entity/view.hpp

+ 1 - 0
TODO

@@ -45,3 +45,4 @@ TODO:
 * suppress -Wself-move on CI with g++13
 * view and view iterator specializations for multi, single and filtered elements
 * organizer support to groups
+* improve none_of in view, avoid checking for validity (especially during each)

+ 14 - 16
src/entt/entity/view.hpp

@@ -248,22 +248,20 @@ protected:
         unchecked_refresh();
     }
 
-    template<std::size_t Index>
-    [[nodiscard]] const Type *storage() const noexcept {
-        if constexpr(Index < Get) {
-            return pools[Index];
-        } else {
-            return filter[Index - Get];
-        }
+    [[nodiscard]] const Type *pool_at(const std::size_t pos) const noexcept {
+        return pools[pos];
     }
 
-    template<std::size_t Index>
-    void storage(const Type *elem) noexcept {
-        if constexpr(Index < Get) {
-            pools[Index] = elem;
+    [[nodiscard]] const Type *storage(const std::size_t pos) const noexcept {
+        return (pos < Get) ? pools[pos] : filter[pos - Get];
+    }
+
+    [[nodiscard]] void storage(const std::size_t pos, const Type *elem) noexcept {
+        if(pos < Get) {
+            pools[pos] = elem;
             refresh();
         } else {
-            filter[Index - Get] = elem;
+            filter[pos - Get] = elem;
         }
     }
 
@@ -432,7 +430,7 @@ class basic_view<get_t<Get...>, exclude_t<Exclude...>, std::enable_if_t<(sizeof.
         static constexpr bool tombstone_check_required = ((sizeof...(Get) == 1u) && ... && (Get::storage_policy == deletion_policy::in_place));
 
         for(const auto curr: storage<Curr>()->each()) {
-            if(const auto entt = std::get<0>(curr); (!tombstone_check_required || (entt != tombstone)) && ((Curr == Index || base_type::template storage<Index>()->contains(entt)) && ...) && base_type::none_of(entt)) {
+            if(const auto entt = std::get<0>(curr); (!tombstone_check_required || (entt != tombstone)) && ((Curr == Index || base_type::pool_at(Index)->contains(entt)) && ...) && base_type::none_of(entt)) {
                 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)...));
                 } else {
@@ -445,7 +443,7 @@ class basic_view<get_t<Get...>, exclude_t<Exclude...>, std::enable_if_t<(sizeof.
     template<typename Func, std::size_t... Index>
     void pick_and_each(Func &func, std::index_sequence<Index...> seq) const {
         if(const auto *view = base_type::handle(); view != nullptr) {
-            ((view == base_type::template storage<Index>() ? each<Index>(func, seq) : void()), ...);
+            ((view == base_type::pool_at(Index) ? each<Index>(func, seq) : void()), ...);
         }
     }
 
@@ -518,7 +516,7 @@ public:
     template<std::size_t Index>
     [[nodiscard]] auto *storage() const noexcept {
         using type = type_list_element_t<Index, type_list<Get..., Exclude...>>;
-        return static_cast<type *>(const_cast<constness_as_t<common_type, type> *>(base_type::template storage<Index>()));
+        return static_cast<type *>(const_cast<constness_as_t<common_type, type> *>(base_type::storage(Index)));
     }
 
     /**
@@ -540,7 +538,7 @@ public:
     template<std::size_t Index, typename Type>
     void storage(Type &elem) noexcept {
         static_assert(std::is_convertible_v<Type &, type_list_element_t<Index, type_list<Get..., Exclude...>> &>, "Unexpected type");
-        base_type::template storage<Index>(&elem);
+        base_type::storage(Index, &elem);
     }
 
     /**