Export of internal Abseil changes
-- d3d344e214e80b766d3e5c355e16124eb8602ff2 by Tom Manshreck <shreck@google.com>: Add LTS Branch to LTS docs PiperOrigin-RevId: 262904704 -- a9b10e6959209e8ded66e5fb041b4f1811a3f375 by CJ Johnson <johnsoncj@google.com>: Minor cleanup on InlinedVector headers PiperOrigin-RevId: 262632981 GitOrigin-RevId: d3d344e214e80b766d3e5c355e16124eb8602ff2 Change-Id: I3d0c078c08520b5c6a1a46c4b681ae0d98297f24
This commit is contained in:
parent
4ef574064e
commit
321ab53030
3 changed files with 18 additions and 15 deletions
1
LTS.md
1
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 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 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/)
|
||||||
|
|
|
@ -533,7 +533,6 @@ class InlinedVector {
|
||||||
}
|
}
|
||||||
|
|
||||||
erase(data() + i, data() + size());
|
erase(data() + i, data() + size());
|
||||||
|
|
||||||
std::copy(first, last, std::back_inserter(*this));
|
std::copy(first, last, std::back_inserter(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -713,6 +712,7 @@ class InlinedVector {
|
||||||
inlined_vector_internal::DestroyElements(storage_.GetAllocPtr(), data(),
|
inlined_vector_internal::DestroyElements(storage_.GetAllocPtr(), data(),
|
||||||
size());
|
size());
|
||||||
storage_.DeallocateIfAllocated();
|
storage_.DeallocateIfAllocated();
|
||||||
|
|
||||||
storage_.SetInlinedSize(0);
|
storage_.SetInlinedSize(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ void DestroyElements(AllocatorType* alloc_ptr, ValueType* destroy_first,
|
||||||
AllocatorTraits::destroy(*alloc_ptr, destroy_first + i);
|
AllocatorTraits::destroy(*alloc_ptr, destroy_first + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#if !defined(NDEBUG)
|
||||||
// Overwrite unused memory with `0xab` so we can catch uninitialized usage.
|
// 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
|
// 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_ptr = static_cast<void*>(destroy_first);
|
||||||
auto memory_size = sizeof(ValueType) * destroy_size;
|
auto memory_size = sizeof(ValueType) * destroy_size;
|
||||||
std::memset(memory_ptr, 0xab, memory_size);
|
std::memset(memory_ptr, 0xab, memory_size);
|
||||||
#endif // NDEBUG
|
#endif // !defined(NDEBUG)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,6 +190,11 @@ class AllocationTransaction {
|
||||||
return GetData();
|
return GetData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Reset() {
|
||||||
|
GetData() = nullptr;
|
||||||
|
GetCapacity() = 0;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
container_internal::CompressedTuple<AllocatorType, pointer> alloc_data_;
|
container_internal::CompressedTuple<AllocatorType, pointer> alloc_data_;
|
||||||
size_type capacity_ = 0;
|
size_type capacity_ = 0;
|
||||||
|
@ -286,8 +291,7 @@ class Storage {
|
||||||
|
|
||||||
Storage() : metadata_() {}
|
Storage() : metadata_() {}
|
||||||
|
|
||||||
explicit Storage(const allocator_type& alloc)
|
explicit Storage(const allocator_type& alloc) : metadata_(alloc, {}) {}
|
||||||
: metadata_(alloc, /* empty and inlined */ 0) {}
|
|
||||||
|
|
||||||
~Storage() {
|
~Storage() {
|
||||||
pointer data = GetIsAllocated() ? GetAllocatedData() : GetInlinedData();
|
pointer data = GetIsAllocated() ? GetAllocatedData() : GetInlinedData();
|
||||||
|
@ -413,8 +417,8 @@ class Storage {
|
||||||
void AcquireAllocatedData(AllocationTransaction* allocation_tx_ptr) {
|
void AcquireAllocatedData(AllocationTransaction* allocation_tx_ptr) {
|
||||||
SetAllocatedData(allocation_tx_ptr->GetData(),
|
SetAllocatedData(allocation_tx_ptr->GetData(),
|
||||||
allocation_tx_ptr->GetCapacity());
|
allocation_tx_ptr->GetCapacity());
|
||||||
allocation_tx_ptr->GetData() = nullptr;
|
|
||||||
allocation_tx_ptr->GetCapacity() = 0;
|
allocation_tx_ptr->Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemcpyFrom(const Storage& other_storage) {
|
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);
|
assert(GetSize() == 0);
|
||||||
|
|
||||||
pointer construct_data;
|
pointer construct_data;
|
||||||
|
|
||||||
if (new_size > GetInlinedCapacity()) {
|
if (new_size > GetInlinedCapacity()) {
|
||||||
// Because this is only called from the `InlinedVector` constructors, it's
|
// Because this is only called from the `InlinedVector` constructors, it's
|
||||||
// safe to take on the allocation with size `0`. If `ConstructElements(...)`
|
// 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) {
|
if (new_size > storage_view.capacity) {
|
||||||
size_type new_capacity = ComputeCapacity(storage_view.capacity, new_size);
|
size_type new_capacity = ComputeCapacity(storage_view.capacity, new_size);
|
||||||
pointer new_data = allocation_tx.Allocate(new_capacity);
|
pointer new_data = allocation_tx.Allocate(new_capacity);
|
||||||
|
|
||||||
construct_loop = {new_data + storage_view.size,
|
construct_loop = {new_data + storage_view.size,
|
||||||
new_size - storage_view.size};
|
new_size - storage_view.size};
|
||||||
move_construct_loop = {new_data, 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));
|
MoveIterator(storage_view.data));
|
||||||
|
|
||||||
pointer construct_data;
|
pointer construct_data;
|
||||||
|
|
||||||
if (storage_view.size == storage_view.capacity) {
|
if (storage_view.size == storage_view.capacity) {
|
||||||
size_type new_capacity = NextCapacity(storage_view.capacity);
|
size_type new_capacity = NextCapacity(storage_view.capacity);
|
||||||
pointer new_data = allocation_tx.Allocate(new_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;
|
construct_data = storage_view.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
pointer end = construct_data + storage_view.size;
|
AllocatorTraits::construct(*GetAllocPtr(), construct_data + storage_view.size,
|
||||||
|
std::forward<Args>(args)...);
|
||||||
AllocatorTraits::construct(*GetAllocPtr(), end, std::forward<Args>(args)...);
|
|
||||||
|
|
||||||
if (allocation_tx.DidAllocate()) {
|
if (allocation_tx.DidAllocate()) {
|
||||||
ABSL_INTERNAL_TRY {
|
ABSL_INTERNAL_TRY {
|
||||||
|
@ -707,7 +709,8 @@ auto Storage<T, N, A>::EmplaceBack(Args&&... args) -> reference {
|
||||||
storage_view.size);
|
storage_view.size);
|
||||||
}
|
}
|
||||||
ABSL_INTERNAL_CATCH_ANY {
|
ABSL_INTERNAL_CATCH_ANY {
|
||||||
AllocatorTraits::destroy(*GetAllocPtr(), end);
|
AllocatorTraits::destroy(*GetAllocPtr(),
|
||||||
|
construct_data + storage_view.size);
|
||||||
ABSL_INTERNAL_RETHROW;
|
ABSL_INTERNAL_RETHROW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -720,7 +723,7 @@ auto Storage<T, N, A>::EmplaceBack(Args&&... args) -> reference {
|
||||||
}
|
}
|
||||||
|
|
||||||
AddSize(1);
|
AddSize(1);
|
||||||
return *end;
|
return *(construct_data + storage_view.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, size_t N, typename A>
|
template <typename T, size_t N, typename A>
|
||||||
|
@ -792,7 +795,6 @@ auto Storage<T, N, A>::ShrinkToFit() -> void {
|
||||||
MoveIterator(storage_view.data));
|
MoveIterator(storage_view.data));
|
||||||
|
|
||||||
pointer construct_data;
|
pointer construct_data;
|
||||||
|
|
||||||
if (storage_view.size > GetInlinedCapacity()) {
|
if (storage_view.size > GetInlinedCapacity()) {
|
||||||
size_type new_capacity = storage_view.size;
|
size_type new_capacity = storage_view.size;
|
||||||
pointer new_data = allocation_tx.Allocate(new_capacity);
|
pointer new_data = allocation_tx.Allocate(new_capacity);
|
||||||
|
|
Loading…
Add table
Reference in a new issue