diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/memory/tempbuf.h | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/memory/tempbuf.h')
-rw-r--r-- | util/memory/tempbuf.h | 132 |
1 files changed, 66 insertions, 66 deletions
diff --git a/util/memory/tempbuf.h b/util/memory/tempbuf.h index 334670eb1e..02c376f658 100644 --- a/util/memory/tempbuf.h +++ b/util/memory/tempbuf.h @@ -1,103 +1,103 @@ #pragma once - + #include <util/system/defaults.h> #include <util/generic/ptr.h> - -/* - * This is really fast buffer for temporary data. - * For small sizes it works almost fast as pure alloca() - * (by using perthreaded list of free blocks), - * for big sizes it works as fast as malloc()/operator new()/... - */ -class TTempBuf { -public: - /* - * we do not want many friends for this class :) - */ - class TImpl; - - TTempBuf(); - TTempBuf(size_t len); + +/* + * This is really fast buffer for temporary data. + * For small sizes it works almost fast as pure alloca() + * (by using perthreaded list of free blocks), + * for big sizes it works as fast as malloc()/operator new()/... + */ +class TTempBuf { +public: + /* + * we do not want many friends for this class :) + */ + class TImpl; + + TTempBuf(); + TTempBuf(size_t len); TTempBuf(const TTempBuf& b) noexcept; TTempBuf(TTempBuf&& b) noexcept; ~TTempBuf(); - + TTempBuf& operator=(const TTempBuf& b) noexcept; TTempBuf& operator=(TTempBuf&& b) noexcept; + + Y_PURE_FUNCTION char* Data() noexcept; - Y_PURE_FUNCTION char* Data() noexcept; - - Y_PURE_FUNCTION const char* Data() const noexcept; + Y_PURE_FUNCTION const char* Data() const noexcept; - Y_PURE_FUNCTION char* Current() noexcept; + Y_PURE_FUNCTION char* Current() noexcept; - Y_PURE_FUNCTION const char* Current() const noexcept; + Y_PURE_FUNCTION const char* Current() const noexcept; - Y_PURE_FUNCTION size_t Size() const noexcept; + Y_PURE_FUNCTION size_t Size() const noexcept; - Y_PURE_FUNCTION size_t Filled() const noexcept; + Y_PURE_FUNCTION size_t Filled() const noexcept; - Y_PURE_FUNCTION size_t Left() const noexcept; + Y_PURE_FUNCTION size_t Left() const noexcept; void Reset() noexcept; - void SetPos(size_t off); + void SetPos(size_t off); char* Proceed(size_t off); - void Append(const void* data, size_t len); - - Y_PURE_FUNCTION bool IsNull() const noexcept; - -private: - TIntrusivePtr<TImpl> Impl_; -}; - -template <typename T> + void Append(const void* data, size_t len); + + Y_PURE_FUNCTION bool IsNull() const noexcept; + +private: + TIntrusivePtr<TImpl> Impl_; +}; + +template <typename T> class TTempArray: private TTempBuf { -private: +private: static T* TypedPointer(char* pointer) noexcept { - return reinterpret_cast<T*>(pointer); - } + return reinterpret_cast<T*>(pointer); + } static const T* TypedPointer(const char* pointer) noexcept { - return reinterpret_cast<const T*>(pointer); - } + return reinterpret_cast<const T*>(pointer); + } static constexpr size_t RawSize(const size_t size) noexcept { - return size * sizeof(T); - } + return size * sizeof(T); + } static constexpr size_t TypedSize(const size_t size) noexcept { - return size / sizeof(T); - } + return size / sizeof(T); + } -public: +public: TTempArray() = default; - TTempArray(size_t len) - : TTempBuf(RawSize(len)) - { - } - + TTempArray(size_t len) + : TTempBuf(RawSize(len)) + { + } + T* Data() noexcept { - return TypedPointer(TTempBuf::Data()); - } + return TypedPointer(TTempBuf::Data()); + } const T* Data() const noexcept { - return TypedPointer(TTempBuf::Data()); - } + return TypedPointer(TTempBuf::Data()); + } T* Current() noexcept { - return TypedPointer(TTempBuf::Current()); - } - + return TypedPointer(TTempBuf::Current()); + } + const T* Current() const noexcept { - return TypedPointer(TTempBuf::Current()); - } + return TypedPointer(TTempBuf::Current()); + } size_t Size() const noexcept { - return TypedSize(TTempBuf::Size()); - } + return TypedSize(TTempBuf::Size()); + } size_t Filled() const noexcept { - return TypedSize(TTempBuf::Filled()); - } - + return TypedSize(TTempBuf::Filled()); + } + T* Proceed(size_t off) { return (T*)TTempBuf::Proceed(RawSize(off)); - } + } }; |