about summary refs log tree commit diff
path: root/absl
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2019-08-12T12·36-0700
committervslashg <gfalcon@google.com>2019-08-12T16·14-0400
commit321ab5303023c86cd15d9ddc5740fb4b4fde32e1 (patch)
tree9106679e6f5f6ecc9170922c3202ff81c04a5f71 /absl
parent4ef574064e75b86f115549e9eb4c7e806781b3ab (diff)
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
Diffstat (limited to 'absl')
-rw-r--r--absl/container/inlined_vector.h2
-rw-r--r--absl/container/internal/inlined_vector.h30
2 files changed, 17 insertions, 15 deletions
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);