aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsabdenovch <sabdenovch@yandex-team.com>2025-01-16 13:07:25 +0300
committersabdenovch <sabdenovch@yandex-team.com>2025-01-16 13:26:49 +0300
commit0059cdd47f567210befb78198fee61c7e824faf8 (patch)
tree75d54bd8ec75684d70f145bacc47bc09485c0b30
parent1b44ecad7ca01cc2506bd4afbe2b8d911e655122 (diff)
downloadydb-0059cdd47f567210befb78198fee61c7e824faf8.tar.gz
Babenkoed: Shadow Wars
commit_hash:deadebefdfd81b6c737b9464435356b8f652e296
-rw-r--r--library/cpp/yt/memory/chunked_memory_allocator.h2
-rw-r--r--library/cpp/yt/memory/chunked_memory_pool-inl.h2
-rw-r--r--library/cpp/yt/memory/ref-inl.h14
-rw-r--r--library/cpp/yt/misc/concepts.h17
-rw-r--r--yt/yt/client/table_client/row_buffer.h4
5 files changed, 29 insertions, 10 deletions
diff --git a/library/cpp/yt/memory/chunked_memory_allocator.h b/library/cpp/yt/memory/chunked_memory_allocator.h
index d5e56c9f70..372fa5ce7e 100644
--- a/library/cpp/yt/memory/chunked_memory_allocator.h
+++ b/library/cpp/yt/memory/chunked_memory_allocator.h
@@ -32,7 +32,7 @@ public:
maxSmallBlockSizeRatio,
GetRefCountedTypeCookie<TTag>())
{
- static_assert(sizeof(TTag) <= 1);
+ static_assert(IsEmptyClass<TTag>());
}
//! Allocates #sizes bytes without any alignment.
diff --git a/library/cpp/yt/memory/chunked_memory_pool-inl.h b/library/cpp/yt/memory/chunked_memory_pool-inl.h
index 0faad070e9..c6ed21fbac 100644
--- a/library/cpp/yt/memory/chunked_memory_pool-inl.h
+++ b/library/cpp/yt/memory/chunked_memory_pool-inl.h
@@ -72,7 +72,7 @@ inline TChunkedMemoryPool::TChunkedMemoryPool(
GetRefCountedTypeCookie<TTag>(),
startChunkSize)
{
- static_assert(sizeof(TTag) <= 1);
+ static_assert(IsEmptyClass<TTag>());
}
inline char* TChunkedMemoryPool::AllocateUnaligned(size_t size)
diff --git a/library/cpp/yt/memory/ref-inl.h b/library/cpp/yt/memory/ref-inl.h
index 62a0a4e6b4..1658bce83c 100644
--- a/library/cpp/yt/memory/ref-inl.h
+++ b/library/cpp/yt/memory/ref-inl.h
@@ -4,6 +4,8 @@
#include "ref.h"
#endif
+#include <library/cpp/yt/misc/concepts.h>
+
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
@@ -134,7 +136,7 @@ Y_FORCE_INLINE TSharedRef::operator TRef() const
template <class TTag>
Y_FORCE_INLINE TSharedRef TSharedRef::FromString(TString str)
{
- static_assert(sizeof(TTag) <= 1);
+ static_assert(IsEmptyClass<TTag>());
return FromString(std::move(str), GetRefCountedTypeCookie<TTag>());
}
@@ -146,7 +148,7 @@ Y_FORCE_INLINE TSharedRef TSharedRef::FromString(TString str)
template <class TTag>
Y_FORCE_INLINE TSharedRef TSharedRef::FromString(std::string str)
{
- static_assert(sizeof(TTag) <= 1);
+ static_assert(IsEmptyClass<TTag>());
return FromString(std::move(str), GetRefCountedTypeCookie<TTag>());
}
@@ -163,7 +165,7 @@ Y_FORCE_INLINE TStringBuf TSharedRef::ToStringBuf() const
template <class TTag>
Y_FORCE_INLINE TSharedRef TSharedRef::MakeCopy(TRef ref)
{
- static_assert(sizeof(TTag) <= 1);
+ static_assert(IsEmptyClass<TTag>());
return MakeCopy(ref, GetRefCountedTypeCookie<TTag>());
}
@@ -227,7 +229,7 @@ Y_FORCE_INLINE TSharedMutableRef TSharedMutableRef::AllocatePageAligned(size_t s
template <class TTag>
Y_FORCE_INLINE TSharedMutableRef TSharedMutableRef::MakeCopy(TRef ref)
{
- static_assert(sizeof(TTag) <= 1);
+ static_assert(IsEmptyClass<TTag>());
return MakeCopy(ref, GetRefCountedTypeCookie<TTag>());
}
@@ -247,14 +249,14 @@ Y_FORCE_INLINE TSharedMutableRef TSharedMutableRef::Slice(void* begin, void* end
template <class TTag>
Y_FORCE_INLINE TSharedMutableRef TSharedMutableRef::Allocate(size_t size, TSharedMutableRefAllocateOptions options)
{
- static_assert(sizeof(TTag) <= 1);
+ static_assert(IsEmptyClass<TTag>());
return Allocate(size, options, GetRefCountedTypeCookie<TTag>());
}
template <class TTag>
Y_FORCE_INLINE TSharedMutableRef TSharedMutableRef::AllocatePageAligned(size_t size, TSharedMutableRefAllocateOptions options)
{
- static_assert(sizeof(TTag) <= 1);
+ static_assert(IsEmptyClass<TTag>());
return AllocatePageAligned(size, options, GetRefCountedTypeCookie<TTag>());
}
diff --git a/library/cpp/yt/misc/concepts.h b/library/cpp/yt/misc/concepts.h
index eda0bc163f..61a722d6d6 100644
--- a/library/cpp/yt/misc/concepts.h
+++ b/library/cpp/yt/misc/concepts.h
@@ -30,6 +30,15 @@ public:
(!NoExcept || IsNoThrowInvocable_);
};
+template <class T>
+struct TIsEmpty
+ : public T
+{
+ int Dummy;
+
+ static constexpr bool Value = (sizeof(TIsEmpty) == sizeof(int));
+};
+
} // namespace NDetail
////////////////////////////////////////////////////////////////////////////////
@@ -81,4 +90,12 @@ concept CMutableRawPtr = CRawPtr<T> && !CConstRawPtr<T>;
////////////////////////////////////////////////////////////////////////////////
+template <class T>
+constexpr bool IsEmptyClass()
+{
+ return NDetail::TIsEmpty<T>::Value;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
} // namespace NYT
diff --git a/yt/yt/client/table_client/row_buffer.h b/yt/yt/client/table_client/row_buffer.h
index cd8b5205af..695845eda0 100644
--- a/yt/yt/client/table_client/row_buffer.h
+++ b/yt/yt/client/table_client/row_buffer.h
@@ -39,7 +39,7 @@ public:
TTag(),
startChunkSize)
{
- static_assert(sizeof(TTag) <= 1);
+ static_assert(IsEmptyClass<TTag>());
}
template <class TTag>
@@ -52,7 +52,7 @@ public:
GetRefCountedTypeCookie<TTag>(),
std::move(chunkProvider))
{
- static_assert(sizeof(TTag) <= 1);
+ static_assert(IsEmptyClass<TTag>());
}
TChunkedMemoryPool* GetPool();