From dd89c56c2ad8fe06db8fd199c7ff77c817f0111f Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Tue, 11 Apr 2023 17:54:53 -0700 Subject: inlined_vector: relax the requirements on the move-construction fast path. Don't require a trivial move constructor and trivial destructor. This excludes types that have declared themselves trivially relocatable by another means, like std::unique_ptr. Instead use "is trivially relocatable" directly, which includes all previous types as well as those that have opted in. PiperOrigin-RevId: 523557136 Change-Id: Icea2dbb8f36f99623308155f2e5b1edd8e5bd36b --- absl/container/internal/inlined_vector.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'absl/container/internal/inlined_vector.h') diff --git a/absl/container/internal/inlined_vector.h b/absl/container/internal/inlined_vector.h index 4e628424..e38cd8b1 100644 --- a/absl/container/internal/inlined_vector.h +++ b/absl/container/internal/inlined_vector.h @@ -301,7 +301,7 @@ class Storage { struct ElementwiseConstructPolicy {}; using MoveAssignmentPolicy = absl::conditional_t< - // Fast path: if the value type can be trivally move assigned and + // Fast path: if the value type can be trivially move assigned and // destroyed, and we know the allocator doesn't do anything fancy, then // it's safe for us to simply adopt the contents of the storage for // `other` and remove its own reference to them. It's as if we had @@ -332,7 +332,7 @@ class Storage { // The policy to be used specifically when swapping inlined elements. using SwapInlinedElementsPolicy = absl::conditional_t< - // Fast path: if the value type can be trivally move constructed/assigned + // Fast path: if the value type can be trivially move constructed/assigned // and destroyed, and we know the allocator doesn't do anything fancy, // then it's safe for us to simply swap the bytes in the inline storage. // It's as if we had move-constructed a temporary vector, move-assigned @@ -505,8 +505,10 @@ class Storage { // we know the allocator doesn't do anything fancy, and one of the following // holds: // - // * It's possible to trivially move construct/assign the elements and - // then destroy the source. + // * The elements are trivially relocatable. + // + // * It's possible to trivially assign the elements and then destroy the + // source. // // * It's possible to trivially copy construct/assign the elements. // @@ -517,10 +519,11 @@ class Storage { (std::is_same>::value && ( // First case above - ((absl::is_trivially_move_constructible::value || - absl::is_trivially_move_assignable::value) && - absl::is_trivially_destructible::value) || + absl::is_trivially_relocatable::value || // Second case above + (absl::is_trivially_move_assignable::value && + absl::is_trivially_destructible::value) || + // Third case above (absl::is_trivially_copy_constructible::value || absl::is_trivially_copy_assignable::value)))); } -- cgit v1.2.3