diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /util/memory/addstorage.h | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'util/memory/addstorage.h')
-rw-r--r-- | util/memory/addstorage.h | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/util/memory/addstorage.h b/util/memory/addstorage.h index e335fcdeca..597c73a988 100644 --- a/util/memory/addstorage.h +++ b/util/memory/addstorage.h @@ -1,81 +1,81 @@ #pragma once - -#include <util/system/align.h> + +#include <util/system/align.h> #include <util/system/defaults.h> - -#include <new> - + +#include <new> + namespace NPrivate { class TAdditionalStorageInfo { - public: + public: constexpr TAdditionalStorageInfo(size_t length) noexcept : Length_(length) { - } - + } + constexpr size_t Length() const noexcept { return Length_; - } - - private: + } + + private: size_t Length_; - }; + }; } - + template <class T> class alignas(::NPrivate::TAdditionalStorageInfo) TAdditionalStorage { using TInfo = ::NPrivate::TAdditionalStorageInfo; -public: +public: inline TAdditionalStorage() noexcept = default; - + inline ~TAdditionalStorage() = default; - - inline void* operator new(size_t len1, size_t len2) { + + 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)); - + return data; - } - + } + inline void operator delete(void* ptr) noexcept { - DoDelete(ptr); - } - + DoDelete(ptr); + } + inline void operator delete(void* ptr, size_t) noexcept { - DoDelete(ptr); - } - + DoDelete(ptr); + } + inline void operator delete(void* ptr, size_t, size_t) noexcept { - /* - * this delete operator can be called automagically by compiler - */ - - DoDelete(ptr); - } - + /* + * this delete operator can be called automagically by compiler + */ + + DoDelete(ptr); + } + inline void* AdditionalData() const noexcept { return (char*)(static_cast<const T*>(this)) + CombinedSizeOfInstanceWithTInfo(); - } - + } + static inline T* ObjectFromData(void* data) noexcept { return reinterpret_cast<T*>(static_cast<char*>(data) - CombinedSizeOfInstanceWithTInfo()); - } - + } + inline size_t AdditionalDataLength() const noexcept { return InfoPtr(static_cast<const T*>(this))->Length(); - } - -private: + } + +private: static inline void DoDelete(void* ptr) noexcept { TInfo* info = InfoPtr(static_cast<T*>(ptr)); - info->~TInfo(); + info->~TInfo(); ::operator delete(ptr); - } - + } + static constexpr size_t CombinedSizeOfInstanceWithTInfo() noexcept { return AlignUp(sizeof(T), alignof(TInfo)) + sizeof(TInfo); } @@ -88,6 +88,6 @@ private: return reinterpret_cast<const TInfo*>(reinterpret_cast<const char*>(instance) + CombinedSizeOfInstanceWithTInfo() - sizeof(TInfo)); } -private: +private: void* operator new(size_t) = delete; -}; +}; |