Skip to content

Commit

Permalink
Align the elements of the array and not the array itself.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-perron committed Mar 30, 2023
1 parent f88675b commit f02d0da
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion source/util/small_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,14 @@ class SmallVector {
// The number of elements in |small_data_| that have been constructed.
size_t size_;

// A type with the same alignment and size as T, but will is POD.
struct alignas(T) PodType {
std::array<std::byte, sizeof(T)> data;
};

// The actual data used to store the array elements. It must never be used
// directly, but must only be accessed through |small_data_|.
alignas(T) std::array<std::byte, sizeof(T) * small_size> buffer;
std::array<PodType, small_size> buffer;

// The pointed used to access the array of elements when the number of
// elements is small.
Expand Down

0 comments on commit f02d0da

Please sign in to comment.