Commit 6cc6ac44 by Abseil Team Committed by Jon Cohen

Export of internal Abseil changes.

--
4a7dc9bd72a50f493671ea3ae2a571462cb70fc4 by Jon Cohen <cohenjon@google.com>:

Use -ignore instead of /ignore.  CMake was interpreting /ignore as a path and changing it it \ignore in windows builds, expecting it to be some sort of file.

Close #293

PiperOrigin-RevId: 242134552

--
8de3e403667f677859584bb321ef8fce3253af18 by CJ Johnson <johnsoncj@google.com>:

In InlinedVector: Migrates `Rep` to `Data` getting rid of the `Allocation` class.

PiperOrigin-RevId: 242130255
GitOrigin-RevId: 4a7dc9bd72a50f493671ea3ae2a571462cb70fc4
Change-Id: Ic7ff4c572bba7a411155bf304b9cae10d68599db
parent 666fc126
...@@ -33,8 +33,6 @@ template <template <typename, size_t, typename> class InlinedVector, typename T, ...@@ -33,8 +33,6 @@ template <template <typename, size_t, typename> class InlinedVector, typename T,
size_t N, typename A> size_t N, typename A>
class Storage<InlinedVector<T, N, A>> { class Storage<InlinedVector<T, N, A>> {
public: public:
class Allocation; // TODO(johnsoncj): Remove after migration
using allocator_type = A; using allocator_type = A;
using value_type = typename allocator_type::value_type; using value_type = typename allocator_type::value_type;
using pointer = typename allocator_type::pointer; using pointer = typename allocator_type::pointer;
...@@ -48,6 +46,7 @@ class Storage<InlinedVector<T, N, A>> { ...@@ -48,6 +46,7 @@ class Storage<InlinedVector<T, N, A>> {
using const_iterator = const_pointer; using const_iterator = const_pointer;
using reverse_iterator = std::reverse_iterator<iterator>; using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>; using const_reverse_iterator = std::reverse_iterator<const_iterator>;
using AllocatorTraits = std::allocator_traits<allocator_type>;
explicit Storage(const allocator_type& alloc) explicit Storage(const allocator_type& alloc)
: metadata_(alloc, /* empty and inlined */ 0) {} : metadata_(alloc, /* empty and inlined */ 0) {}
...@@ -56,30 +55,25 @@ class Storage<InlinedVector<T, N, A>> { ...@@ -56,30 +55,25 @@ class Storage<InlinedVector<T, N, A>> {
bool GetIsAllocated() const { return GetSizeAndIsAllocated() & 1; } bool GetIsAllocated() const { return GetSizeAndIsAllocated() & 1; }
Allocation& GetAllocation() {
return reinterpret_cast<Allocation&>(rep_.allocation_storage.allocation);
}
const Allocation& GetAllocation() const {
return reinterpret_cast<const Allocation&>(
rep_.allocation_storage.allocation);
}
pointer GetInlinedData() { pointer GetInlinedData() {
return reinterpret_cast<pointer>( return reinterpret_cast<pointer>(
std::addressof(rep_.inlined_storage.inlined[0])); std::addressof(data_.inlined.inlined_data[0]));
} }
const_pointer GetInlinedData() const { const_pointer GetInlinedData() const {
return reinterpret_cast<const_pointer>( return reinterpret_cast<const_pointer>(
std::addressof(rep_.inlined_storage.inlined[0])); std::addressof(data_.inlined.inlined_data[0]));
} }
pointer GetAllocatedData() { return GetAllocation().buffer(); } pointer GetAllocatedData() { return data_.allocated.allocated_data; }
const_pointer GetAllocatedData() const { return GetAllocation().buffer(); } const_pointer GetAllocatedData() const {
return data_.allocated.allocated_data;
}
size_type GetAllocatedCapacity() const { return GetAllocation().capacity(); } size_type GetAllocatedCapacity() const {
return data_.allocated.allocated_capacity;
}
allocator_type& GetAllocator() { return metadata_.template get<0>(); } allocator_type& GetAllocator() { return metadata_.template get<0>(); }
...@@ -95,34 +89,23 @@ class Storage<InlinedVector<T, N, A>> { ...@@ -95,34 +89,23 @@ class Storage<InlinedVector<T, N, A>> {
void AddSize(size_type count) { GetSizeAndIsAllocated() += count << 1; } void AddSize(size_type count) { GetSizeAndIsAllocated() += count << 1; }
void InitAllocation(const Allocation& allocation) { void SetAllocatedData(pointer data) {
new (static_cast<void*>(std::addressof(rep_.allocation_storage.allocation))) data_.allocated.allocated_data = data;
Allocation(allocation); }
void SetAllocatedCapacity(size_type capacity) {
data_.allocated.allocated_capacity = capacity;
} }
void SwapSizeAndIsAllocated(Storage& other) { void SwapSizeAndIsAllocated(Storage* other) {
using std::swap; using std::swap;
swap(GetSizeAndIsAllocated(), other.GetSizeAndIsAllocated()); swap(GetSizeAndIsAllocated(), other->GetSizeAndIsAllocated());
} }
// TODO(johnsoncj): Make the below types private after migration void SwapAllocatedSizeAndCapacity(Storage* other) {
class Allocation { using std::swap;
size_type capacity_; swap(data_.allocated, other->data_.allocated);
pointer buffer_; }
public:
Allocation(allocator_type& a, size_type capacity)
: capacity_(capacity), buffer_(Create(a, capacity)) {}
void Dealloc(allocator_type& a) {
std::allocator_traits<allocator_type>::deallocate(a, buffer_, capacity_);
}
size_type capacity() const { return capacity_; }
const_pointer buffer() const { return buffer_; }
pointer buffer() { return buffer_; }
static pointer Create(allocator_type& a, size_type n) {
return std::allocator_traits<allocator_type>::allocate(a, n);
}
};
private: private:
size_type& GetSizeAndIsAllocated() { return metadata_.template get<1>(); } size_type& GetSizeAndIsAllocated() { return metadata_.template get<1>(); }
...@@ -131,29 +114,27 @@ class Storage<InlinedVector<T, N, A>> { ...@@ -131,29 +114,27 @@ class Storage<InlinedVector<T, N, A>> {
return metadata_.template get<1>(); return metadata_.template get<1>();
} }
// Stores either the inlined or allocated representation using Metadata =
union Rep { container_internal::CompressedTuple<allocator_type, size_type>;
using ValueTypeBuffer =
absl::aligned_storage_t<sizeof(value_type), alignof(value_type)>;
using AllocationBuffer =
absl::aligned_storage_t<sizeof(Allocation), alignof(Allocation)>;
// Structs wrap the buffers to perform indirection that solves a bizarre struct Allocated {
// compilation error on Visual Studio (all known versions). pointer allocated_data;
struct InlinedRep { size_type allocated_capacity;
ValueTypeBuffer inlined[N]; };
};
struct AllocatedRep { struct Inlined {
AllocationBuffer allocation; using InlinedDataElement =
}; absl::aligned_storage_t<sizeof(value_type), alignof(value_type)>;
InlinedDataElement inlined_data[N];
};
InlinedRep inlined_storage; union Data {
AllocatedRep allocation_storage; Allocated allocated;
Inlined inlined;
}; };
container_internal::CompressedTuple<allocator_type, size_type> metadata_; Metadata metadata_;
Rep rep_; Data data_;
}; };
} // namespace inlined_vector_internal } // namespace inlined_vector_internal
......
...@@ -204,7 +204,7 @@ list(APPEND ABSL_MSVC_FLAGS ...@@ -204,7 +204,7 @@ list(APPEND ABSL_MSVC_FLAGS
) )
list(APPEND ABSL_MSVC_LINKOPTS list(APPEND ABSL_MSVC_LINKOPTS
"/ignore:4221" "-ignore:4221"
) )
list(APPEND ABSL_MSVC_TEST_FLAGS list(APPEND ABSL_MSVC_TEST_FLAGS
......
...@@ -205,7 +205,7 @@ ABSL_MSVC_FLAGS = [ ...@@ -205,7 +205,7 @@ ABSL_MSVC_FLAGS = [
] ]
ABSL_MSVC_LINKOPTS = [ ABSL_MSVC_LINKOPTS = [
"/ignore:4221", "-ignore:4221",
] ]
ABSL_MSVC_TEST_FLAGS = [ ABSL_MSVC_TEST_FLAGS = [
......
...@@ -189,6 +189,6 @@ COPT_VARS = { ...@@ -189,6 +189,6 @@ COPT_VARS = {
MSVC_STYLE_EXCEPTIONS_FLAGS, MSVC_STYLE_EXCEPTIONS_FLAGS,
"ABSL_MSVC_LINKOPTS": [ "ABSL_MSVC_LINKOPTS": [
# Object file doesn't export any previously undefined symbols # Object file doesn't export any previously undefined symbols
"/ignore:4221", "-ignore:4221",
], ],
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment