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/draft/memory.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/draft/memory.h')
-rw-r--r-- | util/draft/memory.h | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/util/draft/memory.h b/util/draft/memory.h index 0a9722bb36..512c7cfcef 100644 --- a/util/draft/memory.h +++ b/util/draft/memory.h @@ -1,30 +1,30 @@ #pragma once -#include <util/system/defaults.h> - +#include <util/system/defaults.h> + #include <algorithm> #include <functional> #include <utility> -template <class T> -inline bool IsZero(const T* begin, const T* end) { +template <class T> +inline bool IsZero(const T* begin, const T* end) { return std::find_if(begin, end, [](const T& other) { return other != T(0); }) == end; } -template <size_t Size> -inline bool IsZero(const char* p) { - size_t sizeInUI64 = Size / 8; - const char* pEndUi64 = p + sizeInUI64 * 8; +template <size_t Size> +inline bool IsZero(const char* p) { + size_t sizeInUI64 = Size / 8; + const char* pEndUi64 = p + sizeInUI64 * 8; if (sizeInUI64 && !IsZero<ui64>((const ui64*)p, (const ui64*)pEndUi64)) return false; return IsZero(pEndUi64, p + Size); } -#define IS_ZERO_INTSZ(INT) \ - template <> \ - inline bool IsZero<sizeof(INT)>(const char* p) { \ - return (*(INT*)p) == INT(0); \ - } +#define IS_ZERO_INTSZ(INT) \ + template <> \ + inline bool IsZero<sizeof(INT)>(const char* p) { \ + return (*(INT*)p) == INT(0); \ + } IS_ZERO_INTSZ(ui8) IS_ZERO_INTSZ(ui16) @@ -34,7 +34,7 @@ IS_ZERO_INTSZ(ui64) #undef IS_ZERO_INTSZ // If you want to use this to check all fields in a struct make sure it's w/o holes or #pragma pack(1) -template <class T> -bool IsZero(const T& t) { +template <class T> +bool IsZero(const T& t) { return IsZero<sizeof(T)>((const char*)&t); } |