diff options
author | babenko <babenko@yandex-team.com> | 2022-08-07 17:29:43 +0300 |
---|---|---|
committer | babenko <babenko@yandex-team.com> | 2022-08-07 17:29:43 +0300 |
commit | e3b2f4c99d645adbb0956e98dd7d38bc01b7db29 (patch) | |
tree | 00fcb67e7026e42d4af185a268606e3f5ba95829 /library/cpp/yt/memory/ref.cpp | |
parent | ccc7c68ba2a051861c8d517c87f293368e0b7c7b (diff) | |
download | ydb-e3b2f4c99d645adbb0956e98dd7d38bc01b7db29.tar.gz |
Introduce TSharedMutableRefAllocateOptions
Diffstat (limited to 'library/cpp/yt/memory/ref.cpp')
-rw-r--r-- | library/cpp/yt/memory/ref.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/library/cpp/yt/memory/ref.cpp b/library/cpp/yt/memory/ref.cpp index d9f2104090..1a6b1830f7 100644 --- a/library/cpp/yt/memory/ref.cpp +++ b/library/cpp/yt/memory/ref.cpp @@ -103,9 +103,9 @@ protected: const TRefCountedTypeCookie Cookie_; #endif - void Initialize(bool initializeStorage) + void Initialize(TSharedMutableRefAllocateOptions options) { - if (initializeStorage) { + if (options.InitializeStorage) { ::memset(static_cast<TDerived*>(this)->GetBegin(), 0, Size_); } #ifdef YT_ENABLE_REF_COUNTED_TRACKING @@ -122,10 +122,10 @@ class TDefaultAllocationHolder , public TWithExtraSpace<TDefaultAllocationHolder> { public: - TDefaultAllocationHolder(size_t size, bool initializeStorage, TRefCountedTypeCookie cookie) + TDefaultAllocationHolder(size_t size, TSharedMutableRefAllocateOptions options, TRefCountedTypeCookie cookie) : TAllocationHolderBase(size, cookie) { - Initialize(initializeStorage); + Initialize(options); } char* GetBegin() @@ -140,11 +140,11 @@ class TPageAlignedAllocationHolder : public TAllocationHolderBase<TPageAlignedAllocationHolder> { public: - TPageAlignedAllocationHolder(size_t size, bool initializeStorage, TRefCountedTypeCookie cookie) + TPageAlignedAllocationHolder(size_t size, TSharedMutableRefAllocateOptions options, TRefCountedTypeCookie cookie) : TAllocationHolderBase(size, cookie) , Begin_(static_cast<char*>(NYTAlloc::AllocatePageAligned(size))) { - Initialize(initializeStorage); + Initialize(options); } ~TPageAlignedAllocationHolder() @@ -210,7 +210,7 @@ TSharedRef TSharedRef::MakeCopy(TRef ref, TRefCountedTypeCookie tagCookie) if (ref.Empty()) { return TSharedRef::MakeEmpty(); } - auto result = TSharedMutableRef::Allocate(ref.Size(), false, tagCookie); + auto result = TSharedMutableRef::Allocate(ref.Size(), {.InitializeStorage = false}, tagCookie); ::memcpy(result.Begin(), ref.Begin(), ref.Size()); return result; } @@ -234,16 +234,16 @@ std::vector<TSharedRef> TSharedRef::Split(size_t partSize) const //////////////////////////////////////////////////////////////////////////////// -TSharedMutableRef TSharedMutableRef::Allocate(size_t size, bool initializeStorage, TRefCountedTypeCookie tagCookie) +TSharedMutableRef TSharedMutableRef::Allocate(size_t size, TSharedMutableRefAllocateOptions options, TRefCountedTypeCookie tagCookie) { - auto holder = NewWithExtraSpace<TDefaultAllocationHolder>(size, size, initializeStorage, tagCookie); + auto holder = NewWithExtraSpace<TDefaultAllocationHolder>(size, size, options, tagCookie); auto ref = holder->GetRef(); return TSharedMutableRef(ref, std::move(holder)); } -TSharedMutableRef TSharedMutableRef::AllocatePageAligned(size_t size, bool initializeStorage, TRefCountedTypeCookie tagCookie) +TSharedMutableRef TSharedMutableRef::AllocatePageAligned(size_t size, TSharedMutableRefAllocateOptions options, TRefCountedTypeCookie tagCookie) { - auto holder = New<TPageAlignedAllocationHolder>(size, initializeStorage, tagCookie); + auto holder = New<TPageAlignedAllocationHolder>(size, options, tagCookie); auto ref = holder->GetRef(); return TSharedMutableRef(ref, std::move(holder)); } @@ -263,7 +263,7 @@ TSharedMutableRef TSharedMutableRef::MakeCopy(TRef ref, TRefCountedTypeCookie ta if (ref.Empty()) { return TSharedMutableRef::MakeEmpty(); } - auto result = Allocate(ref.Size(), false, tagCookie); + auto result = Allocate(ref.Size(), {.InitializeStorage = false}, tagCookie); ::memcpy(result.Begin(), ref.Begin(), ref.Size()); return result; } |