diff options
-rw-r--r-- | LTS.md | 1 | ||||
-rw-r--r-- | absl/container/inlined_vector.h | 2 | ||||
-rw-r--r-- | absl/container/internal/inlined_vector.h | 30 |
3 files changed, 18 insertions, 15 deletions
diff --git a/LTS.md b/LTS.md index 08606f157e99..94363b6a36f1 100644 --- a/LTS.md +++ b/LTS.md @@ -12,3 +12,4 @@ The following lists LTS branches and the dates on which they have been released: * [LTS Branch December 18, 2018](https://github.com/abseil/abseil-cpp/tree/lts_2018_12_18/) * [LTS Branch June 20, 2018](https://github.com/abseil/abseil-cpp/tree/lts_2018_06_20/) +* [LTS Branch August 8, 2019](https://github.com/abseil/abseil-cpp/tree/lts_2019_08_08/) diff --git a/absl/container/inlined_vector.h b/absl/container/inlined_vector.h index 25af1658914c..5138348a15e5 100644 --- a/absl/container/inlined_vector.h +++ b/absl/container/inlined_vector.h @@ -533,7 +533,6 @@ class InlinedVector { } erase(data() + i, data() + size()); - std::copy(first, last, std::back_inserter(*this)); } @@ -713,6 +712,7 @@ class InlinedVector { inlined_vector_internal::DestroyElements(storage_.GetAllocPtr(), data(), size()); storage_.DeallocateIfAllocated(); + storage_.SetInlinedSize(0); } diff --git a/absl/container/internal/inlined_vector.h b/absl/container/internal/inlined_vector.h index 61c4f6ebfccc..d7c616cfb368 100644 --- a/absl/container/internal/inlined_vector.h +++ b/absl/container/internal/inlined_vector.h @@ -56,7 +56,7 @@ void DestroyElements(AllocatorType* alloc_ptr, ValueType* destroy_first, AllocatorTraits::destroy(*alloc_ptr, destroy_first + i); } -#ifndef NDEBUG +#if !defined(NDEBUG) // Overwrite unused memory with `0xab` so we can catch uninitialized usage. // // Cast to `void*` to tell the compiler that we don't care that we might be @@ -64,7 +64,7 @@ void DestroyElements(AllocatorType* alloc_ptr, ValueType* destroy_first, auto* memory_ptr = static_cast<void*>(destroy_first); auto memory_size = sizeof(ValueType) * destroy_size; std::memset(memory_ptr, 0xab, memory_size); -#endif // NDEBUG +#endif // !defined(NDEBUG) } } @@ -190,6 +190,11 @@ class AllocationTransaction { return GetData(); } + void Reset() { + GetData() = nullptr; + GetCapacity() = 0; + } + private: container_internal::CompressedTuple<AllocatorType, pointer> alloc_data_; size_type capacity_ = 0; @@ -286,8 +291,7 @@ class Storage { Storage() : metadata_() {} - explicit Storage(const allocator_type& alloc) - : metadata_(alloc, /* empty and inlined */ 0) {} + explicit Storage(const allocator_type& alloc) : metadata_(alloc, {}) {} ~Storage() { pointer data = GetIsAllocated() ? GetAllocatedData() : GetInlinedData(); @@ -413,8 +417,8 @@ class Storage { void AcquireAllocatedData(AllocationTransaction* allocation_tx_ptr) { SetAllocatedData(allocation_tx_ptr->GetData(), allocation_tx_ptr->GetCapacity()); - allocation_tx_ptr->GetData() = nullptr; - allocation_tx_ptr->GetCapacity() = 0; + + allocation_tx_ptr->Reset(); } void MemcpyFrom(const Storage& other_storage) { @@ -464,7 +468,6 @@ auto Storage<T, N, A>::Initialize(ValueAdapter values, size_type new_size) assert(GetSize() == 0); pointer construct_data; - if (new_size > GetInlinedCapacity()) { // Because this is only called from the `InlinedVector` constructors, it's // safe to take on the allocation with size `0`. If `ConstructElements(...)` @@ -551,6 +554,7 @@ auto Storage<T, N, A>::Resize(ValueAdapter values, size_type new_size) -> void { if (new_size > storage_view.capacity) { size_type new_capacity = ComputeCapacity(storage_view.capacity, new_size); pointer new_data = allocation_tx.Allocate(new_capacity); + construct_loop = {new_data + storage_view.size, new_size - storage_view.size}; move_construct_loop = {new_data, storage_view.size}; @@ -686,7 +690,6 @@ auto Storage<T, N, A>::EmplaceBack(Args&&... args) -> reference { MoveIterator(storage_view.data)); pointer construct_data; - if (storage_view.size == storage_view.capacity) { size_type new_capacity = NextCapacity(storage_view.capacity); pointer new_data = allocation_tx.Allocate(new_capacity); @@ -696,9 +699,8 @@ auto Storage<T, N, A>::EmplaceBack(Args&&... args) -> reference { construct_data = storage_view.data; } - pointer end = construct_data + storage_view.size; - - AllocatorTraits::construct(*GetAllocPtr(), end, std::forward<Args>(args)...); + AllocatorTraits::construct(*GetAllocPtr(), construct_data + storage_view.size, + std::forward<Args>(args)...); if (allocation_tx.DidAllocate()) { ABSL_INTERNAL_TRY { @@ -707,7 +709,8 @@ auto Storage<T, N, A>::EmplaceBack(Args&&... args) -> reference { storage_view.size); } ABSL_INTERNAL_CATCH_ANY { - AllocatorTraits::destroy(*GetAllocPtr(), end); + AllocatorTraits::destroy(*GetAllocPtr(), + construct_data + storage_view.size); ABSL_INTERNAL_RETHROW; } @@ -720,7 +723,7 @@ auto Storage<T, N, A>::EmplaceBack(Args&&... args) -> reference { } AddSize(1); - return *end; + return *(construct_data + storage_view.size); } template <typename T, size_t N, typename A> @@ -792,7 +795,6 @@ auto Storage<T, N, A>::ShrinkToFit() -> void { MoveIterator(storage_view.data)); pointer construct_data; - if (storage_view.size > GetInlinedCapacity()) { size_type new_capacity = storage_view.size; pointer new_data = allocation_tx.Allocate(new_capacity); |