diff options
author | halyavin <halyavin@yandex-team.com> | 2022-08-05 13:16:26 +0300 |
---|---|---|
committer | halyavin <halyavin@yandex-team.com> | 2022-08-05 13:16:26 +0300 |
commit | 68d8479d07e0b689ba126cf2c159ae7f11afb9cf (patch) | |
tree | 92289178ebded927b8369e4eb1c931be730c6333 /util/generic | |
parent | f346528af256244b692e713a8b6891957ae58dc6 (diff) | |
download | ydb-68d8479d07e0b689ba126cf2c159ae7f11afb9cf.tar.gz |
Mark clear and reset methods as reinitializing the object.
This means, that moved-from object can be safely used after the call of such method.
This attribute is used by clang-tidy which checks that moved-from objects are not used
unless a reinitialization method is called first.
Diffstat (limited to 'util/generic')
-rw-r--r-- | util/generic/buffer.h | 3 | ||||
-rw-r--r-- | util/generic/hash.h | 19 | ||||
-rw-r--r-- | util/generic/hash_set.h | 14 | ||||
-rw-r--r-- | util/generic/maybe.h | 3 | ||||
-rw-r--r-- | util/generic/ptr.h | 33 | ||||
-rw-r--r-- | util/generic/string.h | 3 |
6 files changed, 41 insertions, 34 deletions
diff --git a/util/generic/buffer.h b/util/generic/buffer.h index 95764674049..a5efe398ce7 100644 --- a/util/generic/buffer.h +++ b/util/generic/buffer.h @@ -4,6 +4,7 @@ #include <util/generic/fwd.h> #include <util/system/align.h> +#include <util/system/compiler.h> #include <util/system/yassert.h> #include <cstring> @@ -46,7 +47,7 @@ public: Pos_ -= n; } - inline void Reset() noexcept { + Y_REINITIALIZES_OBJECT inline void Reset() noexcept { TBuffer().Swap(*this); } diff --git a/util/generic/hash.h b/util/generic/hash.h index 81311cc1ee4..0e2a7cfd12f 100644 --- a/util/generic/hash.h +++ b/util/generic/hash.h @@ -4,6 +4,7 @@ #include "mapfindptr.h" #include <util/memory/alloc.h> +#include <util/system/compiler.h> #include <util/system/type_name.h> #include <util/system/yassert.h> #include <util/str_stl.h> @@ -820,7 +821,7 @@ public: void erase(const_iterator first, const_iterator last); bool reserve(size_type num_elements_hint); - void basic_clear(); + Y_REINITIALIZES_OBJECT void basic_clear(); /** * Clears the hashtable without deallocating the nodes. @@ -841,7 +842,7 @@ public: template <class KeySaver> int save_for_st(IOutputStream* stream, KeySaver& ks, sthash<int, int, THash<int>, TEqualTo<int>, typename KeySaver::TSizeType>* stHash = nullptr) const; - void clear(size_type downsize) { + Y_REINITIALIZES_OBJECT void clear(size_type downsize) { basic_clear(); if (downsize < buckets.size()) { @@ -872,7 +873,7 @@ public: * Alternatively, the user can call `basic_clear`, which doesn't do the * downsizing. */ - void clear() { + Y_REINITIALIZES_OBJECT void clear() { if (num_elements) clear((num_elements * 2 + buckets.size()) / 3); } @@ -1715,13 +1716,13 @@ public: void erase(iterator f, iterator l) { rep.erase(f, l); } - void clear() { + Y_REINITIALIZES_OBJECT void clear() { rep.clear(); } - void clear(size_t downsize_hint) { + Y_REINITIALIZES_OBJECT void clear(size_t downsize_hint) { rep.clear(downsize_hint); } - void basic_clear() { + Y_REINITIALIZES_OBJECT void basic_clear() { rep.basic_clear(); } void release_nodes() { @@ -1981,13 +1982,13 @@ public: void erase(iterator f, iterator l) { rep.erase(f, l); } - void clear() { + Y_REINITIALIZES_OBJECT void clear() { rep.clear(); } - void clear(size_t downsize_hint) { + Y_REINITIALIZES_OBJECT void clear(size_t downsize_hint) { rep.clear(downsize_hint); } - void basic_clear() { + Y_REINITIALIZES_OBJECT void basic_clear() { rep.basic_clear(); } void release_nodes() { diff --git a/util/generic/hash_set.h b/util/generic/hash_set.h index e8088cf23b4..fd8851c2993 100644 --- a/util/generic/hash_set.h +++ b/util/generic/hash_set.h @@ -3,6 +3,8 @@ #include "fwd.h" #include "hash.h" +#include <util/system/compiler.h> + #include <initializer_list> #include <utility> @@ -227,13 +229,13 @@ public: void erase(iterator f, iterator l) { rep.erase(f, l); } - void clear() { + Y_REINITIALIZES_OBJECT void clear() { rep.clear(); } - void clear(size_t downsize_hint) { + Y_REINITIALIZES_OBJECT void clear(size_t downsize_hint) { rep.clear(downsize_hint); } - void basic_clear() { + Y_REINITIALIZES_OBJECT void basic_clear() { rep.basic_clear(); } void release_nodes() { @@ -435,13 +437,13 @@ public: void erase(iterator f, iterator l) { rep.erase(f, l); } - void clear() { + Y_REINITIALIZES_OBJECT void clear() { rep.clear(); } - void clear(size_t downsize_hint) { + Y_REINITIALIZES_OBJECT void clear(size_t downsize_hint) { rep.clear(downsize_hint); } - void basic_clear() { + Y_REINITIALIZES_OBJECT void basic_clear() { rep.basic_clear(); } void release_nodes() { diff --git a/util/generic/maybe.h b/util/generic/maybe.h index 34d21aebcdc..633eb1b8435 100644 --- a/util/generic/maybe.h +++ b/util/generic/maybe.h @@ -6,6 +6,7 @@ #include "yexception.h" #include <util/system/align.h> +#include <util/system/compiler.h> #include <util/stream/output.h> #include <util/ysaveload.h> @@ -284,7 +285,7 @@ public: return *Data(); } - void Clear() noexcept { + Y_REINITIALIZES_OBJECT void Clear() noexcept { if (Defined()) { this->Defined_ = false; Data()->~T(); diff --git a/util/generic/ptr.h b/util/generic/ptr.h index db076e7e113..3addc85753e 100644 --- a/util/generic/ptr.h +++ b/util/generic/ptr.h @@ -9,8 +9,9 @@ #include <utility> -#include <util/system/yassert.h> +#include <util/system/compiler.h> #include <util/system/defaults.h> +#include <util/system/yassert.h> template <class T, class U> using TGuardConversion = typename std::enable_if_t<std::is_convertible<U*, T*>::value>; @@ -189,14 +190,14 @@ public: return this->DoRelease(T_); } - inline void Reset(T* t) noexcept { + Y_REINITIALIZES_OBJECT inline void Reset(T* t) noexcept { if (T_ != t) { DoDestroy(); T_ = t; } } - inline void Reset() noexcept { + Y_REINITIALIZES_OBJECT inline void Reset() noexcept { Destroy(); } @@ -284,18 +285,18 @@ public: return this->DoRelease(T_); } - inline void Reset(T* t) noexcept { + Y_REINITIALIZES_OBJECT inline void Reset(T* t) noexcept { if (T_ != t) { DoDestroy(); T_ = t; } } - inline void Reset(TAutoPtr<T, D> t) noexcept { + Y_REINITIALIZES_OBJECT inline void Reset(TAutoPtr<T, D> t) noexcept { Reset(t.Release()); } - inline void Reset() noexcept { + Y_REINITIALIZES_OBJECT inline void Reset() noexcept { Destroy(); } @@ -546,11 +547,11 @@ public: // Effectively replace both: // Reset(const TIntrusivePtr&) // Reset(TIntrusivePtr&&) - inline void Reset(TIntrusivePtr t) noexcept { + Y_REINITIALIZES_OBJECT inline void Reset(TIntrusivePtr t) noexcept { Swap(t); } - inline void Reset() noexcept { + Y_REINITIALIZES_OBJECT inline void Reset() noexcept { Drop(); } @@ -666,11 +667,11 @@ public: // Effectively replace both: // Reset(const TIntrusiveConstPtr&) // Reset(TIntrusiveConstPtr&&) - inline void Reset(TIntrusiveConstPtr t) noexcept { + Y_REINITIALIZES_OBJECT inline void Reset(TIntrusiveConstPtr t) noexcept { Swap(t); } - inline void Reset() noexcept { + Y_REINITIALIZES_OBJECT inline void Reset() noexcept { Drop(); } @@ -865,11 +866,11 @@ public: // Effectively replace both: // Reset(const TSharedPtr& t) // Reset(TSharedPtr&& t) - inline void Reset(TSharedPtr t) noexcept { + Y_REINITIALIZES_OBJECT inline void Reset(TSharedPtr t) noexcept { Swap(t); } - inline void Reset() noexcept { + Y_REINITIALIZES_OBJECT inline void Reset() noexcept { Drop(); } @@ -1015,14 +1016,14 @@ public: return DoRelease(T_); } - inline void Reset(T* t) noexcept { + Y_REINITIALIZES_OBJECT inline void Reset(T* t) noexcept { if (T_ != t) { DoDestroy(); T_ = t; } } - inline void Reset() noexcept { + Y_REINITIALIZES_OBJECT inline void Reset() noexcept { Destroy(); } @@ -1094,11 +1095,11 @@ public: T_.Swap(r.T_); } - inline void Reset(TCowPtr p) { + Y_REINITIALIZES_OBJECT inline void Reset(TCowPtr p) { p.Swap(*this); } - inline void Reset() { + Y_REINITIALIZES_OBJECT inline void Reset() { T_.Reset(); } diff --git a/util/generic/string.h b/util/generic/string.h index fedde9e787d..5f569544816 100644 --- a/util/generic/string.h +++ b/util/generic/string.h @@ -8,6 +8,7 @@ #include <string> #include <string_view> +#include <util/system/compiler.h> #include <util/system/yassert.h> #include "ptr.h" @@ -561,7 +562,7 @@ private: } public: - inline void clear() noexcept { + Y_REINITIALIZES_OBJECT inline void clear() noexcept { #ifdef TSTRING_IS_STD_STRING Storage_.clear(); #else |