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

view: avoid delegating constructors with tuples

Michele Caini пре 3 година
родитељ
комит
f57975acca
2 измењених фајлова са 11 додато и 13 уклоњено
  1. 4 8
      src/entt/entity/registry.hpp
  2. 7 5
      src/entt/entity/view.hpp

+ 4 - 8
src/entt/entity/registry.hpp

@@ -1214,19 +1214,15 @@ public:
      */
     template<typename Component, typename... Other, typename... Exclude>
     [[nodiscard]] auto view(exclude_t<Exclude...> = {}) const {
-        return basic_view{std::forward_as_tuple(
-                              assure<std::remove_const_t<Component>>(),
-                              assure<std::remove_const_t<Other>>()...),
-                          std::forward_as_tuple(assure<std::remove_const_t<Exclude>>()...)};
+        using view_type = basic_view<Entity, get_t<const Component, const Other...>, exclude_t<const Exclude...>>;
+        return view_type{assure<std::remove_const_t<Component>>(), assure<std::remove_const_t<Other>>()..., assure<std::remove_const_t<Exclude>>()...};
     }
 
     /*! @copydoc view */
     template<typename Component, typename... Other, typename... Exclude>
     [[nodiscard]] auto view(exclude_t<Exclude...> = {}) {
-        return basic_view{std::forward_as_tuple(
-                              static_cast<storage_for_t<Component, entity_type> &>(assure<std::remove_const_t<Component>>()),
-                              static_cast<storage_for_t<Other, entity_type> &>(assure<std::remove_const_t<Other>>())...),
-                          std::forward_as_tuple(static_cast<storage_for_t<Exclude, entity_type> &>(assure<std::remove_const_t<Exclude>>())...)};
+        using view_type = basic_view<Entity, get_t<Component, Other...>, exclude_t<Exclude...>>;
+        return view_type{assure<std::remove_const_t<Component>>(), assure<std::remove_const_t<Other>>()..., assure<std::remove_const_t<Exclude>>()...};
     }
 
     /**

+ 7 - 5
src/entt/entity/view.hpp

@@ -257,7 +257,9 @@ public:
      * @param epool The storage for the types used to filter the view.
      */
     basic_view(storage_for_t<Component, entity_type> &...component, storage_for_t<Exclude, entity_type> &...epool) noexcept
-        : basic_view{std::forward_as_tuple(component...), std::forward_as_tuple(epool...)} {}
+        : pools{&component...},
+          filter{&epool...},
+          view{(std::min)({&static_cast<const base_type &>(component)...}, [](auto *lhs, auto *rhs) { return lhs->size() < rhs->size(); })} {}
 
     /**
      * @brief Constructs a multi-type view from a set of storage classes.
@@ -566,16 +568,16 @@ public:
      * @param ref The storage for the type to iterate.
      */
     basic_view(storage_for_t<Component, entity_type> &ref) noexcept
-        : basic_view{std::forward_as_tuple(ref)} {}
+        : pools{&ref},
+          filter{},
+          view{&ref} {}
 
     /**
      * @brief Constructs a single-type view from a storage class.
      * @param ref The storage for the type to iterate.
      */
     basic_view(std::tuple<storage_for_t<Component, entity_type> &> ref, std::tuple<> = {}) noexcept
-        : pools{&std::get<0>(ref)},
-          filter{},
-          view{&std::get<0>(ref)} {}
+        : basic_view{std::get<0>(ref)} {}
 
     /**
      * @brief Returns the leading storage of a view.