diff options
author | ignat <ignat@yandex-team.ru> | 2022-02-10 16:48:20 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:20 +0300 |
commit | c8b279dd21ddcb47e755028d81281f113a0f4a11 (patch) | |
tree | 59384fcb7e8e0566cac1ed9738ab30f0b2559b58 /library/cpp/yt/memory | |
parent | 2096e85a73bb6b3b20ae25a92943992717fe4167 (diff) | |
download | ydb-c8b279dd21ddcb47e755028d81281f113a0f4a11.tar.gz |
Restoring authorship annotation for <ignat@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/yt/memory')
-rw-r--r-- | library/cpp/yt/memory/blob.cpp | 18 | ||||
-rw-r--r-- | library/cpp/yt/memory/blob.h | 12 | ||||
-rw-r--r-- | library/cpp/yt/memory/intrusive_ptr.h | 10 | ||||
-rw-r--r-- | library/cpp/yt/memory/ref.cpp | 22 | ||||
-rw-r--r-- | library/cpp/yt/memory/ref.h | 192 | ||||
-rw-r--r-- | library/cpp/yt/memory/weak_ptr.h | 2 |
6 files changed, 128 insertions, 128 deletions
diff --git a/library/cpp/yt/memory/blob.cpp b/library/cpp/yt/memory/blob.cpp index 86000b033b..d67630d37b 100644 --- a/library/cpp/yt/memory/blob.cpp +++ b/library/cpp/yt/memory/blob.cpp @@ -206,19 +206,19 @@ void TBlob::SetTagCookie(const TBlob& other) #endif } -void swap(TBlob& left, TBlob& right) -{ - if (&left != &right) { - std::swap(left.Begin_, right.Begin_); - std::swap(left.Size_, right.Size_); - std::swap(left.Capacity_, right.Capacity_); +void swap(TBlob& left, TBlob& right) +{ + if (&left != &right) { + std::swap(left.Begin_, right.Begin_); + std::swap(left.Size_, right.Size_); + std::swap(left.Capacity_, right.Capacity_); std::swap(left.PageAligned_, right.PageAligned_); #ifdef YT_ENABLE_REF_COUNTED_TRACKING std::swap(left.TagCookie_, right.TagCookie_); #endif - } -} - + } +} + //////////////////////////////////////////////////////////////////////////////// } // namespace NYT diff --git a/library/cpp/yt/memory/blob.h b/library/cpp/yt/memory/blob.h index 99441fb8c9..0fe1bcbd11 100644 --- a/library/cpp/yt/memory/blob.h +++ b/library/cpp/yt/memory/blob.h @@ -187,11 +187,11 @@ public: //! Appends a single char to the end. void Append(char ch); - //! Swaps the current and other instances - void Swap(TBlob& other); - - friend void swap(TBlob& left, TBlob& right); + //! Swaps the current and other instances + void Swap(TBlob& other); + friend void swap(TBlob& left, TBlob& right); + private: char* Begin_ = nullptr; size_t Size_ = 0; @@ -213,8 +213,8 @@ private: void SetTagCookie(const TBlob& other); }; -void swap(TBlob& left, TBlob& right); - +void swap(TBlob& left, TBlob& right); + //////////////////////////////////////////////////////////////////////////////// } // namespace NYT diff --git a/library/cpp/yt/memory/intrusive_ptr.h b/library/cpp/yt/memory/intrusive_ptr.h index 3dead7db1d..76b8f55fb4 100644 --- a/library/cpp/yt/memory/intrusive_ptr.h +++ b/library/cpp/yt/memory/intrusive_ptr.h @@ -3,11 +3,11 @@ #include "ref_counted.h" #include <util/generic/hash.h> -#include <util/generic/utility.h> - -#include <utility> +#include <util/generic/utility.h> + +#include <utility> #include <type_traits> - + namespace NYT { //////////////////////////////////////////////////////////////////////////////// @@ -110,7 +110,7 @@ public: } //! Move assignment operator. - TIntrusivePtr& operator=(TIntrusivePtr&& other) noexcept + TIntrusivePtr& operator=(TIntrusivePtr&& other) noexcept { TIntrusivePtr(std::move(other)).Swap(*this); return *this; diff --git a/library/cpp/yt/memory/ref.cpp b/library/cpp/yt/memory/ref.cpp index e8ff42e976..c84a1f3f96 100644 --- a/library/cpp/yt/memory/ref.cpp +++ b/library/cpp/yt/memory/ref.cpp @@ -5,8 +5,8 @@ #include <util/system/info.h> -namespace NYT { - +namespace NYT { + //////////////////////////////////////////////////////////////////////////////// namespace NDetail { @@ -275,20 +275,20 @@ TString ToString(TRef ref) } TString ToString(const TMutableRef& ref) -{ - return ToString(TRef(ref)); -} - +{ + return ToString(TRef(ref)); +} + TString ToString(const TSharedRef& ref) { return ToString(TRef(ref)); } TString ToString(const TSharedMutableRef& ref) -{ - return ToString(TRef(ref)); -} - +{ + return ToString(TRef(ref)); +} + size_t GetPageSize() { static const size_t PageSize = NSystemInfo::GetPageSize(); @@ -375,4 +375,4 @@ TSharedRefArray TSharedRefArrayBuilder::Finish() //////////////////////////////////////////////////////////////////////////////// -} // namespace NYT +} // namespace NYT diff --git a/library/cpp/yt/memory/ref.h b/library/cpp/yt/memory/ref.h index 73d19d9013..d89fca702c 100644 --- a/library/cpp/yt/memory/ref.h +++ b/library/cpp/yt/memory/ref.h @@ -1,7 +1,7 @@ #pragma once #include "new.h" -#include "range.h" +#include "range.h" #include "shared_range.h" #include <type_traits> @@ -13,80 +13,80 @@ namespace NYT { // Forward declaration. class TBlob; -//! A non-owning reference to a range of memory. +//! A non-owning reference to a range of memory. class TRef - : public TRange<char> + : public TRange<char> { public: - //! Creates a null TRef. + //! Creates a null TRef. TRef() = default; - //! Creates a TRef for a given block of memory. + //! Creates a TRef for a given block of memory. TRef(const void* data, size_t size); - //! Creates a TRef for a given range of memory. + //! Creates a TRef for a given range of memory. TRef(const void* begin, const void* end); //! Creates an empty TRef. static TRef MakeEmpty(); - //! Creates a non-owning TRef for a given blob. + //! Creates a non-owning TRef for a given blob. static TRef FromBlob(const TBlob& blob); - //! Creates a non-owning TRef for a given string. + //! Creates a non-owning TRef for a given string. static TRef FromString(const TString& str); //! Creates a non-owning TRef for a given stringbuf. static TRef FromStringBuf(TStringBuf strBuf); - //! Creates a non-owning TRef for a given pod structure. + //! Creates a non-owning TRef for a given pod structure. template <class T> static TRef FromPod(const T& data); - - //! Creates a TRef for a part of existing range. + + //! Creates a TRef for a part of existing range. TRef Slice(size_t startOffset, size_t endOffset) const; - //! Compares the content for bitwise equality. + //! Compares the content for bitwise equality. static bool AreBitwiseEqual(TRef lhs, TRef rhs); -}; - -//////////////////////////////////////////////////////////////////////////////// - -//! A non-owning reference to a mutable range of memory. -//! Use with caution :) -class TMutableRef - : public TMutableRange<char> -{ -public: - //! Creates a null TMutableRef. +}; + +//////////////////////////////////////////////////////////////////////////////// + +//! A non-owning reference to a mutable range of memory. +//! Use with caution :) +class TMutableRef + : public TMutableRange<char> +{ +public: + //! Creates a null TMutableRef. //! Note empty TMutableRef is not the same as null TMutableRef. //! `operator bool` can be used to check if ref is nonnull. TMutableRef() = default; - - //! Creates a TMutableRef for a given block of memory. + + //! Creates a TMutableRef for a given block of memory. TMutableRef(void* data, size_t size); - - //! Creates a TMutableRef for a given range of memory. + + //! Creates a TMutableRef for a given range of memory. TMutableRef(void* begin, void* end); - + //! Creates an empty TMutableRef. static TMutableRef MakeEmpty(); - //! Converts a TMutableRef to TRef. + //! Converts a TMutableRef to TRef. operator TRef() const; - //! Creates a non-owning TMutableRef for a given blob. + //! Creates a non-owning TMutableRef for a given blob. static TMutableRef FromBlob(TBlob& blob); - //! Creates a non-owning TMutableRef for a given pod structure. - template <class T> + //! Creates a non-owning TMutableRef for a given pod structure. + template <class T> static TMutableRef FromPod(T& data); - //! Creates a non-owning TMutableRef for a given string. - //! Ensures that the string is not shared. + //! Creates a non-owning TMutableRef for a given string. + //! Ensures that the string is not shared. static TMutableRef FromString(TString& str); - //! Creates a TMutableRef for a part of existing range. + //! Creates a TMutableRef for a part of existing range. TMutableRef Slice(size_t startOffset, size_t endOffset) const; }; @@ -101,16 +101,16 @@ struct TDefaultSharedBlobTag { }; //! A reference to a range of memory with shared ownership. class TSharedRef - : public TSharedRange<char> + : public TSharedRange<char> { public: - //! Creates a null TSharedRef. + //! Creates a null TSharedRef. TSharedRef() = default; - //! Creates a TSharedRef with a given holder. + //! Creates a TSharedRef with a given holder. TSharedRef(TRef ref, THolderPtr holder); - //! Creates a TSharedRef from a pointer and length. + //! Creates a TSharedRef from a pointer and length. TSharedRef(const void* data, size_t length, THolderPtr holder); //! Creates a TSharedRef from a range. @@ -119,39 +119,39 @@ public: //! Creates an empty TSharedRef. static TSharedRef MakeEmpty(); - //! Converts a TSharedRef to TRef. + //! Converts a TSharedRef to TRef. operator TRef() const; - //! Creates a TSharedRef from a string. + //! Creates a TSharedRef from a string. //! Since strings are ref-counted, no data is copied. //! The memory is marked with a given tag. template <class TTag> static TSharedRef FromString(TString str); - //! Creates a TSharedRef from a string. + //! Creates a TSharedRef from a string. //! Since strings are ref-counted, no data is copied. //! The memory is marked with TDefaultSharedBlobTag. static TSharedRef FromString(TString str); - //! Creates a TSharedRef reference from a string. + //! Creates a TSharedRef reference from a string. //! Since strings are ref-counted, no data is copied. //! The memory is marked with a given tag. static TSharedRef FromString(TString str, TRefCountedTypeCookie tagCookie); - //! Creates a TSharedRef for a given blob taking ownership of its content. + //! Creates a TSharedRef for a given blob taking ownership of its content. static TSharedRef FromBlob(TBlob&& blob); - //! Creates a copy of a given TRef. - //! The memory is marked with a given tag. + //! Creates a copy of a given TRef. + //! The memory is marked with a given tag. static TSharedRef MakeCopy(TRef ref, TRefCountedTypeCookie tagCookie); - - //! Creates a copy of a given TRef. - //! The memory is marked with a given tag. - template <class TTag> + + //! Creates a copy of a given TRef. + //! The memory is marked with a given tag. + template <class TTag> static TSharedRef MakeCopy(TRef ref); - //! Creates a TSharedRef for a part of existing range. + //! Creates a TSharedRef for a part of existing range. TSharedRef Slice(size_t startOffset, size_t endOffset) const; //! Creates a TSharedRef for a part of existing range. @@ -160,54 +160,54 @@ public: //! Creates a vector of slices with specified size. std::vector<TSharedRef> Split(size_t partSize) const; -private: +private: friend class TSharedRefArrayImpl; -}; - -//////////////////////////////////////////////////////////////////////////////// - -//! A reference to a mutable range of memory with shared ownership. -//! Use with caution :) -class TSharedMutableRef - : public TSharedMutableRange<char> -{ -public: - //! Creates a null TSharedMutableRef. +}; + +//////////////////////////////////////////////////////////////////////////////// + +//! A reference to a mutable range of memory with shared ownership. +//! Use with caution :) +class TSharedMutableRef + : public TSharedMutableRange<char> +{ +public: + //! Creates a null TSharedMutableRef. TSharedMutableRef() = default; - - //! Creates a TSharedMutableRef with a given holder. + + //! Creates a TSharedMutableRef with a given holder. TSharedMutableRef(const TMutableRef& ref, THolderPtr holder); - - //! Creates a TSharedMutableRef from a pointer and length. + + //! Creates a TSharedMutableRef from a pointer and length. TSharedMutableRef(void* data, size_t length, THolderPtr holder); - + //! Creates a TSharedMutableRef from a range. TSharedMutableRef(void* begin, void* end, THolderPtr holder); - + //! Creates an empty TSharedMutableRef. static TSharedMutableRef MakeEmpty(); - //! Converts a TSharedMutableRef to TMutableRef. + //! Converts a TSharedMutableRef to TMutableRef. operator TMutableRef() const; - //! Converts a TSharedMutableRef to TSharedRef. + //! Converts a TSharedMutableRef to TSharedRef. operator TSharedRef() const; - //! Converts a TSharedMutableRef to TRef. + //! Converts a TSharedMutableRef to TRef. operator TRef() const; - - //! Allocates a new shared block of memory. - //! The memory is marked with a given tag. - template <class TTag> + + //! Allocates a new shared block of memory. + //! The memory is marked with a given tag. + template <class TTag> static TSharedMutableRef Allocate(size_t size, bool initializeStorage = true); - //! Allocates a new shared block of memory. - //! The memory is marked with TDefaultSharedBlobTag. + //! Allocates a new shared block of memory. + //! The memory is marked with TDefaultSharedBlobTag. static TSharedMutableRef Allocate(size_t size, bool initializeStorage = true); - //! Allocates a new shared block of memory. - //! The memory is marked with a given tag. + //! Allocates a new shared block of memory. + //! The memory is marked with a given tag. static TSharedMutableRef Allocate(size_t size, bool initializeStorage, TRefCountedTypeCookie tagCookie); //! Allocates a new page aligned shared block of memory. @@ -226,22 +226,22 @@ public: //! The memory is marked with a given tag. static TSharedMutableRef AllocatePageAligned(size_t size, bool initializeStorage, TRefCountedTypeCookie tagCookie); - //! Creates a TSharedMutableRef for the whole blob taking ownership of its content. + //! Creates a TSharedMutableRef for the whole blob taking ownership of its content. static TSharedMutableRef FromBlob(TBlob&& blob); - //! Creates a copy of a given TRef. - //! The memory is marked with a given tag. + //! Creates a copy of a given TRef. + //! The memory is marked with a given tag. static TSharedMutableRef MakeCopy(TRef ref, TRefCountedTypeCookie tagCookie); - //! Creates a copy of a given TRef. - //! The memory is marked with a given tag. - template <class TTag> + //! Creates a copy of a given TRef. + //! The memory is marked with a given tag. + template <class TTag> static TSharedMutableRef MakeCopy(TRef ref); - //! Creates a reference for a part of existing range. + //! Creates a reference for a part of existing range. TSharedMutableRef Slice(size_t startOffset, size_t endOffset) const; - //! Creates a reference for a part of existing range. + //! Creates a reference for a part of existing range. TSharedMutableRef Slice(void* begin, void* end) const; }; @@ -270,13 +270,13 @@ public: template <class TParts> TSharedRefArray(TParts&& parts, TMoveParts); - TSharedRefArray& operator = (const TSharedRefArray& other); - TSharedRefArray& operator = (TSharedRefArray&& other); + TSharedRefArray& operator = (const TSharedRefArray& other); + TSharedRefArray& operator = (TSharedRefArray&& other); explicit operator bool() const; - void Reset(); - + void Reset(); + size_t Size() const; size_t size() const; i64 ByteSize() const; @@ -303,7 +303,7 @@ private: As&&... args); }; -// STL interop. +// STL interop. const TSharedRef* begin(const TSharedRefArray& array); const TSharedRef* end(const TSharedRefArray& array); @@ -364,17 +364,17 @@ TString ToString(TRef ref); TString ToString(const TMutableRef& ref); TString ToString(const TSharedRef& ref); TString ToString(const TSharedMutableRef& ref); - + size_t GetPageSize(); size_t RoundUpToPage(size_t bytes); size_t GetByteSize(TRef ref); size_t GetByteSize(const TSharedRefArray& array); -template <class T> +template <class T> size_t GetByteSize(TRange<T> parts); template <class T> size_t GetByteSize(const std::vector<T>& parts); - + //////////////////////////////////////////////////////////////////////////////// } // namespace NYT diff --git a/library/cpp/yt/memory/weak_ptr.h b/library/cpp/yt/memory/weak_ptr.h index 25a242bb8a..d1647dc6e1 100644 --- a/library/cpp/yt/memory/weak_ptr.h +++ b/library/cpp/yt/memory/weak_ptr.h @@ -128,7 +128,7 @@ public: } //! Move assignment operator. - TWeakPtr& operator=(TWeakPtr&& other) noexcept + TWeakPtr& operator=(TWeakPtr&& other) noexcept { other.Swap(*this); return *this; |