From 321ab5303023c86cd15d9ddc5740fb4b4fde32e1 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 12 Aug 2019 05:36:06 -0700 Subject: Export of internal Abseil changes -- d3d344e214e80b766d3e5c355e16124eb8602ff2 by Tom Manshreck : Add LTS Branch to LTS docs PiperOrigin-RevId: 262904704 -- a9b10e6959209e8ded66e5fb041b4f1811a3f375 by CJ Johnson : Minor cleanup on InlinedVector headers PiperOrigin-RevId: 262632981 GitOrigin-RevId: d3d344e214e80b766d3e5c355e16124eb8602ff2 Change-Id: I3d0c078c08520b5c6a1a46c4b681ae0d98297f24 --- LTS.md | 1 + absl/container/inlined_vector.h | 2 +- absl/container/internal/inlined_vector.h | 30 ++++++++++++++++-------------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/LTS.md b/LTS.md index 08606f1..94363b6 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 25af165..5138348 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 61c4f6e..d7c616c 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(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 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::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::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::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::EmplaceBack(Args&&... args) -> reference { construct_data = storage_view.data; } - pointer end = construct_data + storage_view.size; - - AllocatorTraits::construct(*GetAllocPtr(), end, std::forward(args)...); + AllocatorTraits::construct(*GetAllocPtr(), construct_data + storage_view.size, + std::forward(args)...); if (allocation_tx.DidAllocate()) { ABSL_INTERNAL_TRY { @@ -707,7 +709,8 @@ auto Storage::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::EmplaceBack(Args&&... args) -> reference { } AddSize(1); - return *end; + return *(construct_data + storage_view.size); } template @@ -792,7 +795,6 @@ auto Storage::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); -- cgit v1.2.3