aboutsummaryrefslogtreecommitdiffstats
path: root/util/memory/addstorage.h
diff options
context:
space:
mode:
authorswarmer <swarmer@yandex-team.ru>2022-02-10 16:46:31 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:31 +0300
commit317da38588b7898a99fd9168571408123350012b (patch)
tree25eebc31526019ad39a6c1b13f492963d97ba439 /util/memory/addstorage.h
parent3b2241461d41d41ba1a706b0750c4f0f55c344f6 (diff)
downloadydb-317da38588b7898a99fd9168571408123350012b.tar.gz
Restoring authorship annotation for <swarmer@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/memory/addstorage.h')
-rw-r--r--util/memory/addstorage.h74
1 files changed, 37 insertions, 37 deletions
diff --git a/util/memory/addstorage.h b/util/memory/addstorage.h
index 597c73a988..81c8260b9d 100644
--- a/util/memory/addstorage.h
+++ b/util/memory/addstorage.h
@@ -5,40 +5,40 @@
#include <new>
-namespace NPrivate {
- class TAdditionalStorageInfo {
+namespace NPrivate {
+ class TAdditionalStorageInfo {
public:
- constexpr TAdditionalStorageInfo(size_t length) noexcept
- : Length_(length)
- {
+ constexpr TAdditionalStorageInfo(size_t length) noexcept
+ : Length_(length)
+ {
}
- constexpr size_t Length() const noexcept {
- return Length_;
+ constexpr size_t Length() const noexcept {
+ return Length_;
}
private:
- size_t Length_;
+ size_t Length_;
};
-}
-
-template <class T>
-class alignas(::NPrivate::TAdditionalStorageInfo) TAdditionalStorage {
- using TInfo = ::NPrivate::TAdditionalStorageInfo;
+}
+template <class T>
+class alignas(::NPrivate::TAdditionalStorageInfo) TAdditionalStorage {
+ using TInfo = ::NPrivate::TAdditionalStorageInfo;
+
public:
inline TAdditionalStorage() noexcept = default;
inline ~TAdditionalStorage() = default;
inline void* operator new(size_t len1, size_t len2) {
- static_assert(alignof(T) >= alignof(TInfo));
- Y_ASSERT(len1 == sizeof(T));
- void* data = ::operator new(CombinedSizeOfInstanceWithTInfo() + len2);
- void* info = InfoPtr(static_cast<T*>(data));
- Y_UNUSED(new (info) TInfo(len2));
+ static_assert(alignof(T) >= alignof(TInfo));
+ Y_ASSERT(len1 == sizeof(T));
+ void* data = ::operator new(CombinedSizeOfInstanceWithTInfo() + len2);
+ void* info = InfoPtr(static_cast<T*>(data));
+ Y_UNUSED(new (info) TInfo(len2));
- return data;
+ return data;
}
inline void operator delete(void* ptr) noexcept {
@@ -58,36 +58,36 @@ public:
}
inline void* AdditionalData() const noexcept {
- return (char*)(static_cast<const T*>(this)) + CombinedSizeOfInstanceWithTInfo();
+ return (char*)(static_cast<const T*>(this)) + CombinedSizeOfInstanceWithTInfo();
}
static inline T* ObjectFromData(void* data) noexcept {
- return reinterpret_cast<T*>(static_cast<char*>(data) - CombinedSizeOfInstanceWithTInfo());
+ return reinterpret_cast<T*>(static_cast<char*>(data) - CombinedSizeOfInstanceWithTInfo());
}
inline size_t AdditionalDataLength() const noexcept {
- return InfoPtr(static_cast<const T*>(this))->Length();
+ return InfoPtr(static_cast<const T*>(this))->Length();
}
private:
static inline void DoDelete(void* ptr) noexcept {
- TInfo* info = InfoPtr(static_cast<T*>(ptr));
+ TInfo* info = InfoPtr(static_cast<T*>(ptr));
info->~TInfo();
- ::operator delete(ptr);
- }
-
- static constexpr size_t CombinedSizeOfInstanceWithTInfo() noexcept {
- return AlignUp(sizeof(T), alignof(TInfo)) + sizeof(TInfo);
- }
-
- static constexpr TInfo* InfoPtr(T* instance) noexcept {
- return const_cast<TInfo*>(InfoPtr(static_cast<const T*>(instance)));
- }
-
- static constexpr const TInfo* InfoPtr(const T* instance) noexcept {
- return reinterpret_cast<const TInfo*>(reinterpret_cast<const char*>(instance) + CombinedSizeOfInstanceWithTInfo() - sizeof(TInfo));
+ ::operator delete(ptr);
}
+ static constexpr size_t CombinedSizeOfInstanceWithTInfo() noexcept {
+ return AlignUp(sizeof(T), alignof(TInfo)) + sizeof(TInfo);
+ }
+
+ static constexpr TInfo* InfoPtr(T* instance) noexcept {
+ return const_cast<TInfo*>(InfoPtr(static_cast<const T*>(instance)));
+ }
+
+ static constexpr const TInfo* InfoPtr(const T* instance) noexcept {
+ return reinterpret_cast<const TInfo*>(reinterpret_cast<const char*>(instance) + CombinedSizeOfInstanceWithTInfo() - sizeof(TInfo));
+ }
+
private:
- void* operator new(size_t) = delete;
+ void* operator new(size_t) = delete;
};