aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authoraleexfi <aleexfi@yandex-team.com>2023-04-07 16:55:40 +0300
committeraleexfi <aleexfi@yandex-team.com>2023-04-07 16:55:40 +0300
commitc2ca4487e67405e557ea3b875106d2b0f3e70429 (patch)
tree9fb3ffe96dea9053a376849d59f7880e97e5614a /library/cpp
parente5ecbf8573a6bcc2b2193dead9e7299994c28db1 (diff)
downloadydb-c2ca4487e67405e557ea3b875106d2b0f3e70429.tar.gz
YT-18375: Get rid of zero size padding
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/yt/small_containers/compact_vector.h13
-rw-r--r--library/cpp/yt/small_containers/unittests/compact_vector_ut.cpp11
2 files changed, 23 insertions, 1 deletions
diff --git a/library/cpp/yt/small_containers/compact_vector.h b/library/cpp/yt/small_containers/compact_vector.h
index 6c4a0b0e39e..23a0ac3fd01 100644
--- a/library/cpp/yt/small_containers/compact_vector.h
+++ b/library/cpp/yt/small_containers/compact_vector.h
@@ -164,17 +164,28 @@ private:
uint8_t SizePlusOne;
} alias_hack;
+ // TODO(aleexfi): Use [[no_unique_address]] when clang will support it on windows.
+ template <class = void>
struct TOnHeapMeta
{
char Padding[ByteSize - sizeof(uintptr_t)];
TOnHeapStorage* Storage;
} alias_hack;
+ template <class _>
+ requires (ByteSize == sizeof(uintptr_t))
+ struct TOnHeapMeta<_>
+ {
+ TOnHeapStorage* Storage;
+ } alias_hack;
+
+ static_assert(sizeof(TOnHeapMeta<>) == ByteSize);
+
union
{
T InlineElements_[N];
TInlineMeta InlineMeta_;
- TOnHeapMeta OnHeapMeta_;
+ TOnHeapMeta<> OnHeapMeta_;
};
bool IsInline() const;
diff --git a/library/cpp/yt/small_containers/unittests/compact_vector_ut.cpp b/library/cpp/yt/small_containers/unittests/compact_vector_ut.cpp
index 33e9f31f9d3..1e30c0a532b 100644
--- a/library/cpp/yt/small_containers/unittests/compact_vector_ut.cpp
+++ b/library/cpp/yt/small_containers/unittests/compact_vector_ut.cpp
@@ -1080,6 +1080,17 @@ TEST(CompactVectorTest, AssignToLonger) {
EXPECT_EQ("foo", lhs[0]);
}
+TEST(CompactVectorTest, ZeroPaddingOnHeapMeta) {
+ TCompactVector<uint8_t, 6> vector;
+ std::vector<uint8_t> expected;
+ for (int i = 0; i < 10; ++i) {
+ vector.push_back(i);
+ expected.push_back(i);
+
+ ASSERT_THAT(vector, ::testing::ElementsAreArray(expected));
+ }
+}
+
////////////////////////////////////////////////////////////////////////////////
} // namespace