registry: better, faster range-remove + refine range-erase
This commit is contained in:
@@ -956,17 +956,28 @@ public:
|
||||
*/
|
||||
template<typename Type, typename... Other, typename It>
|
||||
size_type remove(It first, It last) {
|
||||
if constexpr(sizeof...(Other) == 0u) {
|
||||
return assure<Type>().remove(std::move(first), std::move(last));
|
||||
} else {
|
||||
size_type count{};
|
||||
size_type count{};
|
||||
|
||||
if constexpr(sizeof...(Other) == 0u) {
|
||||
count += assure<Type>().remove(std::move(first), std::move(last));
|
||||
} else if constexpr(std::is_same_v<It, typename basic_common_type::iterator>) {
|
||||
constexpr size_type len = sizeof...(Other) + 1u;
|
||||
basic_common_type *cpools[len]{&assure<Type>(), &assure<Other>()...};
|
||||
|
||||
for(size_type pos{}; pos < len; ++pos) {
|
||||
if(cpools[pos]->data() == first.data()) {
|
||||
std::swap(cpools[pos], cpools[len - 1u]);
|
||||
}
|
||||
|
||||
count += cpools[pos]->remove(first, last);
|
||||
}
|
||||
} else {
|
||||
for(auto cpools = std::forward_as_tuple(assure<Type>(), assure<Other>()...); first != last; ++first) {
|
||||
count += std::apply([entt = *first](auto &...curr) { return (curr.remove(entt) + ... + 0u); }, cpools);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -998,10 +1009,12 @@ public:
|
||||
*/
|
||||
template<typename Type, typename... Other, typename It>
|
||||
void erase(It first, It last) {
|
||||
constexpr size_type len = sizeof...(Other) + 1u;
|
||||
basic_common_type *cpools[len]{&assure<Type>(), &assure<Other>()...};
|
||||
if constexpr(sizeof...(Other) == 0u) {
|
||||
assure<Type>().erase(std::move(first), std::move(last));
|
||||
} else if constexpr(std::is_same_v<It, typename basic_common_type::iterator>) {
|
||||
constexpr size_type len = sizeof...(Other) + 1u;
|
||||
basic_common_type *cpools[len]{&assure<Type>(), &assure<Other>()...};
|
||||
|
||||
if constexpr(std::is_same_v<It, typename basic_common_type::iterator>) {
|
||||
for(size_type pos{}; pos < len; ++pos) {
|
||||
if(cpools[pos]->data() == first.data()) {
|
||||
std::swap(cpools[pos], cpools[len - 1u]);
|
||||
@@ -1010,12 +1023,8 @@ public:
|
||||
cpools[pos]->erase(first, last);
|
||||
}
|
||||
} else {
|
||||
for(; first != last; ++first) {
|
||||
const auto entt = *first;
|
||||
|
||||
for(size_type pos{}; pos < len; ++pos) {
|
||||
cpools[pos]->erase(entt);
|
||||
}
|
||||
for(auto cpools = std::forward_as_tuple(assure<Type>(), assure<Other>()...); first != last; ++first) {
|
||||
std::apply([entt = *first](auto &...curr) { (curr.erase(entt), ...); }, cpools);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user