diff options
author | savrus <savrus@yandex-team.ru> | 2022-02-10 16:50:48 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:48 +0300 |
commit | 2ee4b26133812e990e7958fc1863d8d5f8ee7f7b (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/yt/memory | |
parent | 2056f5ae3bf6e5a65e9885e0add085c708cca5b8 (diff) | |
download | ydb-2ee4b26133812e990e7958fc1863d8d5f8ee7f7b.tar.gz |
Restoring authorship annotation for <savrus@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/yt/memory')
-rw-r--r-- | library/cpp/yt/memory/blob.cpp | 100 | ||||
-rw-r--r-- | library/cpp/yt/memory/blob.h | 60 | ||||
-rw-r--r-- | library/cpp/yt/memory/new-inl.h | 2 | ||||
-rw-r--r-- | library/cpp/yt/memory/range.h | 10 | ||||
-rw-r--r-- | library/cpp/yt/memory/ref.h | 4 |
5 files changed, 88 insertions, 88 deletions
diff --git a/library/cpp/yt/memory/blob.cpp b/library/cpp/yt/memory/blob.cpp index 542592ab28..86000b033b 100644 --- a/library/cpp/yt/memory/blob.cpp +++ b/library/cpp/yt/memory/blob.cpp @@ -21,7 +21,7 @@ TBlob::TBlob( if (size == 0) { Reset(); } else { - Allocate(std::max(size, InitialBlobCapacity)); + Allocate(std::max(size, InitialBlobCapacity)); Size_ = size; if (initiailizeStorage) { ::memset(Begin_, 0, Size_); @@ -34,12 +34,12 @@ TBlob::TBlob( TRef data, bool pageAligned) : PageAligned_(pageAligned) -{ +{ SetTagCookie(tagCookie); - Reset(); + Reset(); Append(data); -} - +} + TBlob::TBlob(const TBlob& other) : PageAligned_(other.PageAligned_) { @@ -47,13 +47,13 @@ TBlob::TBlob(const TBlob& other) if (other.Size_ == 0) { Reset(); } else { - Allocate(std::max(InitialBlobCapacity, other.Size_)); + Allocate(std::max(InitialBlobCapacity, other.Size_)); ::memcpy(Begin_, other.Begin_, other.Size_); Size_ = other.Size_; } } -TBlob::TBlob(TBlob&& other) noexcept +TBlob::TBlob(TBlob&& other) noexcept : Begin_(other.Begin_) , Size_(other.Size_) , Capacity_(other.Capacity_) @@ -65,13 +65,13 @@ TBlob::TBlob(TBlob&& other) noexcept TBlob::~TBlob() { - Free(); + Free(); } void TBlob::Reserve(size_t newCapacity) { if (newCapacity > Capacity_) { - Reallocate(newCapacity); + Reallocate(newCapacity); } } @@ -79,13 +79,13 @@ void TBlob::Resize(size_t newSize, bool initializeStorage /*= true*/) { if (newSize > Size_) { if (newSize > Capacity_) { - size_t newCapacity; + size_t newCapacity; if (Capacity_ == 0) { - newCapacity = std::max(InitialBlobCapacity, newSize); + newCapacity = std::max(InitialBlobCapacity, newSize); } else { - newCapacity = std::max(static_cast<size_t>(Capacity_ * BlobCapacityMultiplier), newSize); + newCapacity = std::max(static_cast<size_t>(Capacity_ * BlobCapacityMultiplier), newSize); } - Reallocate(newCapacity); + Reallocate(newCapacity); } if (initializeStorage) { ::memset(Begin_ + Size_, 0, newSize - Size_); @@ -103,7 +103,7 @@ TBlob& TBlob::operator = (const TBlob& rhs) return *this; } -TBlob& TBlob::operator = (TBlob&& rhs) noexcept +TBlob& TBlob::operator = (TBlob&& rhs) noexcept { if (this != &rhs) { this->~TBlob(); @@ -151,61 +151,61 @@ char* TBlob::DoAllocate(size_t size) : NYTAlloc::Allocate(size)); } -void TBlob::Allocate(size_t newCapacity) -{ +void TBlob::Allocate(size_t newCapacity) +{ YT_VERIFY(!Begin_); Begin_ = DoAllocate(newCapacity); - Capacity_ = newCapacity; -#ifdef YT_ENABLE_REF_COUNTED_TRACKING + Capacity_ = newCapacity; +#ifdef YT_ENABLE_REF_COUNTED_TRACKING TRefCountedTrackerFacade::AllocateTagInstance(TagCookie_); TRefCountedTrackerFacade::AllocateSpace(TagCookie_, newCapacity); -#endif -} +#endif +} -void TBlob::Reallocate(size_t newCapacity) -{ +void TBlob::Reallocate(size_t newCapacity) +{ if (!Begin_) { - Allocate(newCapacity); - return; - } + Allocate(newCapacity); + return; + } char* newBegin = DoAllocate(newCapacity); ::memcpy(newBegin, Begin_, Size_); NYTAlloc::FreeNonNull(Begin_); -#ifdef YT_ENABLE_REF_COUNTED_TRACKING +#ifdef YT_ENABLE_REF_COUNTED_TRACKING TRefCountedTrackerFacade::AllocateSpace(TagCookie_, newCapacity); TRefCountedTrackerFacade::FreeSpace(TagCookie_, Capacity_); -#endif - Begin_ = newBegin; - Capacity_ = newCapacity; -} - -void TBlob::Free() -{ +#endif + Begin_ = newBegin; + Capacity_ = newCapacity; +} + +void TBlob::Free() +{ if (!Begin_) { - return; - } + return; + } NYTAlloc::FreeNonNull(Begin_); -#ifdef YT_ENABLE_REF_COUNTED_TRACKING +#ifdef YT_ENABLE_REF_COUNTED_TRACKING TRefCountedTrackerFacade::FreeTagInstance(TagCookie_); TRefCountedTrackerFacade::FreeSpace(TagCookie_, Capacity_); -#endif +#endif Reset(); -} - +} + void TBlob::SetTagCookie(TRefCountedTypeCookie tagCookie) -{ -#ifdef YT_ENABLE_REF_COUNTED_TRACKING +{ +#ifdef YT_ENABLE_REF_COUNTED_TRACKING TagCookie_ = tagCookie; -#endif -} +#endif +} void TBlob::SetTagCookie(const TBlob& other) -{ -#ifdef YT_ENABLE_REF_COUNTED_TRACKING +{ +#ifdef YT_ENABLE_REF_COUNTED_TRACKING TagCookie_ = other.TagCookie_; -#endif -} - +#endif +} + void swap(TBlob& left, TBlob& right) { if (&left != &right) { @@ -213,9 +213,9 @@ void swap(TBlob& left, TBlob& right) std::swap(left.Size_, right.Size_); std::swap(left.Capacity_, right.Capacity_); std::swap(left.PageAligned_, right.PageAligned_); -#ifdef YT_ENABLE_REF_COUNTED_TRACKING +#ifdef YT_ENABLE_REF_COUNTED_TRACKING std::swap(left.TagCookie_, right.TagCookie_); -#endif +#endif } } diff --git a/library/cpp/yt/memory/blob.h b/library/cpp/yt/memory/blob.h index b03d526cf4..99441fb8c9 100644 --- a/library/cpp/yt/memory/blob.h +++ b/library/cpp/yt/memory/blob.h @@ -1,16 +1,16 @@ #pragma once #include "ref.h" -#include "ref_counted.h" +#include "ref_counted.h" namespace NYT { //////////////////////////////////////////////////////////////////////////////// -//! Default memory tag for TBlob. +//! Default memory tag for TBlob. struct TDefaultBlobTag { }; - + //! A home-grown optimized replacement for |std::vector<char>| suitable for carrying //! large chunks of data. /*! @@ -20,27 +20,27 @@ struct TDefaultBlobTag class TBlob { public: - //! Constructs a blob with a given size. + //! Constructs a blob with a given size. TBlob( TRefCountedTypeCookie tagCookie, size_t size, bool initiailizeStorage = true, bool pageAligned = false); - - //! Copies a chunk of memory into a new instance. + + //! Copies a chunk of memory into a new instance. TBlob( TRefCountedTypeCookie tagCookie, TRef data, bool pageAligned = false); - + //! Constructs an empty blob. - template <class TTag = TDefaultBlobTag> + template <class TTag = TDefaultBlobTag> explicit TBlob(TTag tag = {}) : TBlob(tag, 0, true, false) - { } + { } //! Constructs a blob with a given size. - template <class TTag> + template <class TTag> explicit TBlob( TTag, size_t size, @@ -51,10 +51,10 @@ public: size, initiailizeStorage, pageAligned) - { } + { } - //! Copies a chunk of memory into a new instance. - template <class TTag> + //! Copies a chunk of memory into a new instance. + template <class TTag> TBlob( TTag, TRef data, @@ -63,21 +63,21 @@ public: GetRefCountedTypeCookie<TTag>(), data, pageAligned) - { } - - //! Remind user about the tag argument. - TBlob(i32 size, bool initiailizeStorage = true) = delete; - TBlob(i64 size, bool initiailizeStorage = true) = delete; - TBlob(ui32 size, bool initiailizeStorage = true) = delete; - TBlob(ui64 size, bool initiailizeStorage = true) = delete; + { } + + //! Remind user about the tag argument. + TBlob(i32 size, bool initiailizeStorage = true) = delete; + TBlob(i64 size, bool initiailizeStorage = true) = delete; + TBlob(ui32 size, bool initiailizeStorage = true) = delete; + TBlob(ui64 size, bool initiailizeStorage = true) = delete; template <typename T, typename U> TBlob(const T*, U) = delete; - + //! Copies the data. TBlob(const TBlob& other); //! Moves the data (takes the ownership). - TBlob(TBlob&& other) noexcept; + TBlob(TBlob&& other) noexcept; //! Reclaims the memory. ~TBlob(); @@ -176,7 +176,7 @@ public: TBlob& operator = (const TBlob& rhs); //! Takes the ownership. - TBlob& operator = (TBlob&& rhs) noexcept; + TBlob& operator = (TBlob&& rhs) noexcept; //! Appends a chunk of memory to the end. void Append(const void* data, size_t size); @@ -198,15 +198,15 @@ private: size_t Capacity_ = 0; bool PageAligned_ = false; -#ifdef YT_ENABLE_REF_COUNTED_TRACKING +#ifdef YT_ENABLE_REF_COUNTED_TRACKING TRefCountedTypeCookie TagCookie_ = NullRefCountedTypeCookie; -#endif - +#endif + char* DoAllocate(size_t newCapacity); - void Allocate(size_t newCapacity); - void Reallocate(size_t newCapacity); - void Free(); - + void Allocate(size_t newCapacity); + void Reallocate(size_t newCapacity); + void Free(); + void Reset(); void SetTagCookie(TRefCountedTypeCookie tagCookie); diff --git a/library/cpp/yt/memory/new-inl.h b/library/cpp/yt/memory/new-inl.h index 4e8d70449c..0a84818516 100644 --- a/library/cpp/yt/memory/new-inl.h +++ b/library/cpp/yt/memory/new-inl.h @@ -5,7 +5,7 @@ #endif #include <library/cpp/ytalloc/api/ytalloc.h> - + namespace NYT { //////////////////////////////////////////////////////////////////////////////// diff --git a/library/cpp/yt/memory/range.h b/library/cpp/yt/memory/range.h index 316595f1f3..6c71aa9496 100644 --- a/library/cpp/yt/memory/range.h +++ b/library/cpp/yt/memory/range.h @@ -160,11 +160,11 @@ public: return Length_; } - size_t size() const - { - return Size(); - } - + size_t size() const + { + return Size(); + } + const T& operator[](size_t index) const { YT_ASSERT(index < Size()); diff --git a/library/cpp/yt/memory/ref.h b/library/cpp/yt/memory/ref.h index 44d8bbbb2d..73d19d9013 100644 --- a/library/cpp/yt/memory/ref.h +++ b/library/cpp/yt/memory/ref.h @@ -157,9 +157,9 @@ public: //! Creates a TSharedRef for a part of existing range. TSharedRef Slice(const void* begin, const void* end) const; - //! Creates a vector of slices with specified size. + //! Creates a vector of slices with specified size. std::vector<TSharedRef> Split(size_t partSize) const; - + private: friend class TSharedRefArrayImpl; }; |