diff options
author | yazevnul <yazevnul@yandex-team.ru> | 2022-02-10 16:46:48 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:48 +0300 |
commit | 9abfb1a53b7f7b791444d1378e645d8fad9b06ed (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /util/system/unaligned_mem.h | |
parent | 8cbc307de0221f84c80c42dcbe07d40727537e2c (diff) | |
download | ydb-9abfb1a53b7f7b791444d1378e645d8fad9b06ed.tar.gz |
Restoring authorship annotation for <yazevnul@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/system/unaligned_mem.h')
-rw-r--r-- | util/system/unaligned_mem.h | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/util/system/unaligned_mem.h b/util/system/unaligned_mem.h index 6985270d9e..4b84686f2f 100644 --- a/util/system/unaligned_mem.h +++ b/util/system/unaligned_mem.h @@ -1,7 +1,7 @@ #pragma once #include "defaults.h" -#include "yassert.h" +#include "yassert.h" #include <string.h> #include <type_traits> @@ -23,45 +23,45 @@ template <class T> inline void WriteUnaligned(void* to, const std::remove_reference_t<T>& t) noexcept { memcpy(to, &t, sizeof(T)); } - -template <class T, unsigned Align = sizeof(T)> -class TUnalignedMemoryIterator { -public: - inline TUnalignedMemoryIterator(const void* buf, size_t len) - : C_((const unsigned char*)buf) - , E_(C_ + len) - , L_(E_ - (len % Align)) - { - Y_FAKE_READ(buf); - } - - inline bool AtEnd() const noexcept { - return C_ == L_; - } - - inline T Cur() const noexcept { + +template <class T, unsigned Align = sizeof(T)> +class TUnalignedMemoryIterator { +public: + inline TUnalignedMemoryIterator(const void* buf, size_t len) + : C_((const unsigned char*)buf) + , E_(C_ + len) + , L_(E_ - (len % Align)) + { + Y_FAKE_READ(buf); + } + + inline bool AtEnd() const noexcept { + return C_ == L_; + } + + inline T Cur() const noexcept { Y_ASSERT(C_ < L_ || sizeof(T) < Align); - return ::ReadUnaligned<T>(C_); - } - - inline T Next() noexcept { - T ret(Cur()); - - C_ += sizeof(T); - - return ret; - } - - inline const unsigned char* Last() const noexcept { - return C_; - } - - inline size_t Left() const noexcept { - return E_ - C_; - } - -private: - const unsigned char* C_; - const unsigned char* E_; - const unsigned char* L_; -}; + return ::ReadUnaligned<T>(C_); + } + + inline T Next() noexcept { + T ret(Cur()); + + C_ += sizeof(T); + + return ret; + } + + inline const unsigned char* Last() const noexcept { + return C_; + } + + inline size_t Left() const noexcept { + return E_ - C_; + } + +private: + const unsigned char* C_; + const unsigned char* E_; + const unsigned char* L_; +}; |