storage: refine ::pop to improve perf for trivially destructible types - close #1311

This commit is contained in:
skypjack
2026-02-26 09:33:40 +01:00
parent b1758e221b
commit 79188ad748
3 changed files with 5 additions and 1 deletions

1
TODO
View File

@@ -37,6 +37,5 @@ TODO:
* use the value type mixin more in the test suite to reduce the number of utility types
* explore "runtime" mode for hashed string where the source is copied internally
* swap_only/swap_and_pop/in_place_pop can (should?) accept the entity
* we can likely improve storage::pop for trivially destructible non in_place_delete types
* storage: shrink_to_fit does not work with reentrant destructor?
* test trivially_destructible optimization

View File

@@ -326,6 +326,9 @@ protected:
if constexpr(traits_type::in_place_delete) {
base_type::in_place_pop(first);
alloc_traits::destroy(allocator, std::addressof(elem));
} else if constexpr(std::is_trivially_destructible_v<element_type>) {
elem = std::move(element_at(base_type::size() - 1u));
base_type::swap_and_pop(first);
} else {
auto &other = element_at(base_type::size() - 1u);
// destroying on exit allows reentrant destructors

View File

@@ -16,6 +16,8 @@ struct throwing_type {
}
}
~throwing_type() { /* make it non trivially destructible */ }
throwing_type &operator=(const throwing_type &other) {
trigger = other.trigger;
return *this;