From 86bbb2f6bb9824f9a64fe2248d31a470bc84f915 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Sat, 18 Mar 2023 12:41:11 +0100 Subject: [PATCH] group: reuse pools when sorting --- src/entt/entity/group.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/entt/entity/group.hpp b/src/entt/entity/group.hpp index 167cc3e16..7383d6603 100644 --- a/src/entt/entity/group.hpp +++ b/src/entt/entity/group.hpp @@ -602,11 +602,11 @@ public: static_assert(std::is_invocable_v, "Invalid comparison function"); descriptor->group().sort(std::move(compare), std::move(algo), std::forward(args)...); } else { - auto comp = [this, &compare](const entity_type lhs, const entity_type rhs) { + auto comp = [&compare, cpools = std::forward_as_tuple(storage>()...)](const entity_type lhs, const entity_type rhs) { if constexpr(sizeof...(Type) == 1) { - return compare((storage>().get(lhs), ...), (storage>().get(rhs), ...)); + return compare(std::get<0>(cpools).get(lhs), std::get<0>(cpools).get(rhs)); } else { - return compare(std::forward_as_tuple(storage>().get(lhs)...), std::forward_as_tuple(storage>().get(rhs)...)); + return std::apply([&compare, lhs, rhs](auto &...cpool) { return compare(std::forward_as_tuple(cpool.get(lhs)...), std::forward_as_tuple(cpool.get(rhs)...)); }, cpools); } }; @@ -991,11 +991,11 @@ public: static_assert(std::is_invocable_v, "Invalid comparison function"); storage<0>().sort_n(descriptor->length(), std::move(compare), std::move(algo), std::forward(args)...); } else { - auto comp = [this, &compare](const entity_type lhs, const entity_type rhs) { + auto comp = [&compare, cpools = std::forward_as_tuple(storage>()...)](const entity_type lhs, const entity_type rhs) { if constexpr(sizeof...(Type) == 1) { - return compare((storage>().get(lhs), ...), (storage>().get(rhs), ...)); + return compare(std::get<0>(cpools).get(lhs), std::get<0>(cpools).get(rhs)); } else { - return compare(std::forward_as_tuple(storage>().get(lhs)...), std::forward_as_tuple(storage>().get(rhs)...)); + return std::apply([&compare, lhs, rhs](auto &...cpool) { return compare(std::forward_as_tuple(cpool.get(lhs)...), std::forward_as_tuple(cpool.get(rhs)...)); }, cpools); } };