diff options
| author | lukyan <[email protected]> | 2022-02-10 16:48:13 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:48:13 +0300 | 
| commit | 96647fad5355ff5ef45a00a6d85c097028584ab0 (patch) | |
| tree | b222e5ac2e2e98872661c51ccceee5da0d291e13 /library/cpp/yt/memory/blob.h | |
| parent | 3e359c7e6344b01b8d0b0fc619297ffdc2644c49 (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/yt/memory/blob.h')
| -rw-r--r-- | library/cpp/yt/memory/blob.h | 220 | 
1 files changed, 110 insertions, 110 deletions
| diff --git a/library/cpp/yt/memory/blob.h b/library/cpp/yt/memory/blob.h index 7d1621a09a1..99441fb8c97 100644 --- a/library/cpp/yt/memory/blob.h +++ b/library/cpp/yt/memory/blob.h @@ -1,25 +1,25 @@ -#pragma once  -  +#pragma once +  #include "ref.h"  #include "ref_counted.h" -  -namespace NYT {  -  -////////////////////////////////////////////////////////////////////////////////  -  + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// +  //! Default memory tag for TBlob.  struct TDefaultBlobTag  { }; -//! A home-grown optimized replacement for |std::vector<char>| suitable for carrying  -//! large chunks of data.  -/*!  - *  Compared to |std::vector<char>|, this class supports uninitialized allocations  - *  when explicitly requested to.  - */  -class TBlob  -{  -public:  +//! A home-grown optimized replacement for |std::vector<char>| suitable for carrying +//! large chunks of data. +/*! + *  Compared to |std::vector<char>|, this class supports uninitialized allocations + *  when explicitly requested to. + */ +class TBlob +{ +public:      //! Constructs a blob with a given size.      TBlob(          TRefCountedTypeCookie tagCookie, @@ -33,13 +33,13 @@ public:          TRef data,          bool pageAligned = false); -    //! Constructs an empty blob.  +    //! Constructs an empty blob.      template <class TTag = TDefaultBlobTag>      explicit TBlob(TTag tag = {})          : TBlob(tag, 0, true, false)      { } -  -    //! Constructs a blob with a given size.  + +    //! Constructs a blob with a given size.      template <class TTag>      explicit TBlob(          TTag, @@ -52,7 +52,7 @@ public:              initiailizeStorage,              pageAligned)      { } -  +      //! Copies a chunk of memory into a new instance.      template <class TTag>      TBlob( @@ -73,52 +73,52 @@ public:      template <typename T, typename U>      TBlob(const T*, U) = delete; -    //! Copies the data.  -    TBlob(const TBlob& other);  -  -    //! Moves the data (takes the ownership).  +    //! Copies the data. +    TBlob(const TBlob& other); + +    //! Moves the data (takes the ownership).      TBlob(TBlob&& other) noexcept; -  -    //! Reclaims the memory.  -    ~TBlob();  -  -    //! Ensures that capacity is at least #capacity.  -    void Reserve(size_t newCapacity);  -  -    //! Changes the size to #newSize.  -    /*!  -     *  If #size exceeds the current capacity,  -     *  we make sure the new capacity grows exponentially.  -     *  Hence calling #Resize N times to increase the size by N only  -     *  takes amortized O(1) time per call.  -     */  -    void Resize(size_t newSize, bool initializeStorage = true);  -  -    //! Returns the start pointer.  + +    //! Reclaims the memory. +    ~TBlob(); + +    //! Ensures that capacity is at least #capacity. +    void Reserve(size_t newCapacity); + +    //! Changes the size to #newSize. +    /*! +     *  If #size exceeds the current capacity, +     *  we make sure the new capacity grows exponentially. +     *  Hence calling #Resize N times to increase the size by N only +     *  takes amortized O(1) time per call. +     */ +    void Resize(size_t newSize, bool initializeStorage = true); + +    //! Returns the start pointer.      Y_FORCE_INLINE const char* Begin() const -    {  -        return Begin_;  -    }  -  -    //! Returns the start pointer.  +    { +        return Begin_; +    } + +    //! Returns the start pointer.      Y_FORCE_INLINE char* Begin() -    {  -        return Begin_;  -    }  -  -    //! Returns the end pointer.  +    { +        return Begin_; +    } + +    //! Returns the end pointer.      Y_FORCE_INLINE const char* End() const -    {  -        return Begin_ + Size_;  -    }  -  -    //! Returns the end pointer.  +    { +        return Begin_ + Size_; +    } + +    //! Returns the end pointer.      Y_FORCE_INLINE char* End() -    {  -        return Begin_ + Size_;  -    }  -  -    //! Returns the size.  +    { +        return Begin_ + Size_; +    } + +    //! Returns the size.      Y_FORCE_INLINE size_t size() const      {          return Size_; @@ -126,16 +126,16 @@ public:      //! Returns the size.      Y_FORCE_INLINE size_t Size() const -    {  -        return Size_;  -    }  -  -    //! Returns the capacity.  +    { +        return Size_; +    } + +    //! Returns the capacity.      Y_FORCE_INLINE size_t Capacity() const -    {  -        return Capacity_;  -    }  -  +    { +        return Capacity_; +    } +      //! Returns the TStringBuf instance for the occupied part of the blob.      Y_FORCE_INLINE TStringBuf ToStringBuf() const      { @@ -148,42 +148,42 @@ public:          return TRef(Begin_, Size_);      } -    //! Provides by-value access to the underlying storage.  +    //! Provides by-value access to the underlying storage.      Y_FORCE_INLINE char operator [] (size_t index) const -    {  -        return Begin_[index];  -    }  -  -    //! Provides by-ref access to the underlying storage.  +    { +        return Begin_[index]; +    } + +    //! Provides by-ref access to the underlying storage.      Y_FORCE_INLINE char& operator [] (size_t index) -    {  -        return Begin_[index];  -    }  -  -    //! Clears the instance but does not reclaim the memory.  +    { +        return Begin_[index]; +    } + +    //! Clears the instance but does not reclaim the memory.      Y_FORCE_INLINE void Clear() -    {  -        Size_ = 0;  -    }  -  -    //! Returns |true| if size is zero.  +    { +        Size_ = 0; +    } + +    //! Returns |true| if size is zero.      Y_FORCE_INLINE bool IsEmpty() const -    {  -        return Size_ == 0;  -    }  -  -    //! Overwrites the current instance.  -    TBlob& operator = (const TBlob& rhs);  -  -    //! Takes the ownership.  +    { +        return Size_ == 0; +    } + +    //! Overwrites the current instance. +    TBlob& operator = (const TBlob& rhs); + +    //! Takes the ownership.      TBlob& operator = (TBlob&& rhs) noexcept; -  -    //! Appends a chunk of memory to the end.  -    void Append(const void* data, size_t size);  -  -    //! Appends a chunk of memory to the end.  + +    //! Appends a chunk of memory to the end. +    void Append(const void* data, size_t size); + +    //! Appends a chunk of memory to the end.      void Append(TRef ref); -  +      //! Appends a single char to the end.      void Append(char ch); @@ -192,12 +192,12 @@ public:      friend void swap(TBlob& left, TBlob& right); -private:  +private:      char* Begin_ = nullptr;      size_t Size_ = 0;      size_t Capacity_ = 0;      bool PageAligned_ = false; -  +  #ifdef YT_ENABLE_REF_COUNTED_TRACKING      TRefCountedTypeCookie TagCookie_ = NullRefCountedTypeCookie;  #endif @@ -207,15 +207,15 @@ private:      void Reallocate(size_t newCapacity);      void Free(); -    void Reset();  -  +    void Reset(); +      void SetTagCookie(TRefCountedTypeCookie tagCookie);      void SetTagCookie(const TBlob& other); -};  -  +}; +  void swap(TBlob& left, TBlob& right); -////////////////////////////////////////////////////////////////////////////////  -  -} // namespace NYT  -  +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT + | 
