Skip to content

Commit

Permalink
Export of internal Abseil changes
Browse files Browse the repository at this point in the history
--
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
  • Loading branch information
Abseil Team authored and vslashg committed Aug 12, 2019
1 parent 4ef5740 commit 321ab53
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions LTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
2 changes: 1 addition & 1 deletion absl/container/inlined_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,6 @@ class InlinedVector {
}

erase(data() + i, data() + size());

std::copy(first, last, std::back_inserter(*this));
}

Expand Down Expand Up @@ -713,6 +712,7 @@ class InlinedVector {
inlined_vector_internal::DestroyElements(storage_.GetAllocPtr(), data(),
size());
storage_.DeallocateIfAllocated();

storage_.SetInlinedSize(0);
}

Expand Down
30 changes: 16 additions & 14 deletions absl/container/internal/inlined_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ 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
// scribbling on a vtable pointer.
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)
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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(...)`
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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;
}

Expand All @@ -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>
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 321ab53

Please sign in to comment.