storage: refine ::pop to improve perf for trivially destructible types - close #1311
This commit is contained in:
1
TODO
1
TODO
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user