diff options
author | psushin <psushin@yandex-team.ru> | 2022-02-10 16:49:19 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:19 +0300 |
commit | 4ba0e0cae125e5faa4b5664a88c54ab6af93ea4d (patch) | |
tree | 1c00333319988270b78d83715b1e56fddfa7028e | |
parent | 7622df751aca736b9e1e20015e6787d5a65643b0 (diff) | |
download | ydb-4ba0e0cae125e5faa4b5664a88c54ab6af93ea4d.tar.gz |
Restoring authorship annotation for <psushin@yandex-team.ru>. Commit 1 of 2.
-rw-r--r-- | library/cpp/testing/common/probe.h | 44 | ||||
-rw-r--r-- | library/cpp/testing/gtest_extensions/probe.h | 42 | ||||
-rw-r--r-- | library/cpp/yson/varint.h | 22 | ||||
-rw-r--r-- | library/cpp/yt/coding/varint.h | 40 | ||||
-rw-r--r-- | library/cpp/yt/memory/intrusive_ptr.h | 20 | ||||
-rw-r--r-- | library/cpp/yt/memory/ref.h | 4 | ||||
-rw-r--r-- | library/cpp/yt/memory/ref_tracked.h | 58 | ||||
-rw-r--r-- | library/cpp/yt/memory/weak_ptr.h | 14 | ||||
-rw-r--r-- | library/cpp/yt/small_containers/compact_set.h | 70 |
9 files changed, 157 insertions, 157 deletions
diff --git a/library/cpp/testing/common/probe.h b/library/cpp/testing/common/probe.h index 19910979b5..30090a85a1 100644 --- a/library/cpp/testing/common/probe.h +++ b/library/cpp/testing/common/probe.h @@ -1,13 +1,13 @@ -#pragma once - +#pragma once + #include <util/system/yassert.h> namespace NTesting { //////////////////////////////////////////////////////////////////////////////// - + // Below there is a serie of probe classes for testing construction/destruction copying/moving of class. // for examples see tests in probe_ut.cpp - + struct TProbeState { int Constructors = 0; int Destructors = 0; @@ -17,44 +17,44 @@ namespace NTesting { int MoveConstructors = 0; int MoveAssignments = 0; int Touches = 0; - + TProbeState() = default; - + void Reset() { *this = TProbeState{}; } }; - + // Used for probing the number of copies that occur if a type must be coerced. class TCoercibleToProbe { public: TProbeState* State; TProbeState* ShadowState; - + public: explicit TCoercibleToProbe(TProbeState* state) : State(state) , ShadowState(state) {} - + private: TCoercibleToProbe(const TCoercibleToProbe&); TCoercibleToProbe(TCoercibleToProbe&&); TCoercibleToProbe& operator=(const TCoercibleToProbe&); TCoercibleToProbe& operator=(TCoercibleToProbe&&); }; - + // Used for probing the number of copies in an argument. class TProbe { public: TProbeState* State; TProbeState* ShadowState; - + public: static TProbe ExplicitlyCreateInvalidProbe() { return TProbe(); } - + explicit TProbe(TProbeState* state) : State(state) , ShadowState(state) @@ -62,7 +62,7 @@ namespace NTesting { Y_ASSERT(State); ++State->Constructors; } - + ~TProbe() { if (State) { ++State->Destructors; @@ -71,7 +71,7 @@ namespace NTesting { ++ShadowState->ShadowDestructors; } } - + TProbe(const TProbe& other) : State(other.State) , ShadowState(other.ShadowState) @@ -79,7 +79,7 @@ namespace NTesting { Y_ASSERT(State); ++State->CopyConstructors; } - + TProbe(TProbe&& other) : State(other.State) , ShadowState(other.ShadowState) @@ -88,14 +88,14 @@ namespace NTesting { other.State = nullptr; ++State->MoveConstructors; } - + TProbe(const TCoercibleToProbe& other) : State(other.State) , ShadowState(other.ShadowState) { Y_ASSERT(State); ++State->CopyConstructors; - } + } TProbe(TCoercibleToProbe&& other) : State(other.State) @@ -105,7 +105,7 @@ namespace NTesting { other.State = nullptr; ++State->MoveConstructors; } - + TProbe& operator=(const TProbe& other) { State = other.State; ShadowState = other.ShadowState; @@ -113,7 +113,7 @@ namespace NTesting { ++State->CopyAssignments; return *this; } - + TProbe& operator=(TProbe&& other) { State = other.State; ShadowState = other.ShadowState; @@ -122,16 +122,16 @@ namespace NTesting { ++State->MoveAssignments; return *this; } - + void Touch() const { Y_ASSERT(State); ++State->Touches; } - + bool IsValid() const { return nullptr != State; } - + private: TProbe() : State(nullptr) diff --git a/library/cpp/testing/gtest_extensions/probe.h b/library/cpp/testing/gtest_extensions/probe.h index 7d1fee83d3..0313cd0f98 100644 --- a/library/cpp/testing/gtest_extensions/probe.h +++ b/library/cpp/testing/gtest_extensions/probe.h @@ -1,58 +1,58 @@ -#pragma once - +#pragma once + #include <util/system/yassert.h> #include <library/cpp/testing/common/probe.h> #include <gtest/gtest.h> #include <gmock/gmock.h> - + namespace testing { using NTesting::TProbe; using NTesting::TProbeState; using NTesting::TCoercibleToProbe; - + // A helper functor which extracts from probe-like objectss their state. struct TProbableTraits { static const TProbeState& ExtractState(const TProbeState& probe) { return probe; } - + static const TProbeState& ExtractState(const TProbeState* probe) { return *probe; } - + static const TProbeState& ExtractState(const TProbe& probe) { return *probe.State; } - + static const TProbeState& ExtractState(const TCoercibleToProbe& probe) { return *probe.State; } }; - + void PrintTo(const TProbeState& state, ::std::ostream* os); - + inline void PrintTo(const TProbe& probe, ::std::ostream* os) { PrintTo(TProbableTraits::ExtractState(probe), os); - } - + } + inline void PrintTo(const TCoercibleToProbe& probe, ::std::ostream* os) { PrintTo(TProbableTraits::ExtractState(probe), os); - } - + } + MATCHER(IsAlive, "is alive") { Y_UNUSED(result_listener); const auto& state = TProbableTraits::ExtractState(arg); return state.Destructors < state.Constructors + state.CopyConstructors + state.CopyAssignments; - } - + } + MATCHER(IsDead, "is dead") { Y_UNUSED(result_listener); const auto& state = TProbableTraits::ExtractState(arg); return state.Destructors == state.Constructors + state.CopyConstructors + state.CopyAssignments; - } - + } + MATCHER_P2(HasCopyMoveCounts, copyCount, moveCount, "" + \ PrintToString(copyCount) + " copy constructors and " + \ PrintToString(moveCount) + " move constructors were called") { @@ -60,22 +60,22 @@ namespace testing { const auto& state = TProbableTraits::ExtractState(arg); return state.CopyConstructors == copyCount && state.MoveConstructors == moveCount; } - + MATCHER(NoCopies, "no copies were made") { Y_UNUSED(result_listener); const auto& state = TProbableTraits::ExtractState(arg); return 0 == state.CopyConstructors && 0 == state.CopyAssignments; } - + MATCHER(NoMoves, "no moves were made") { Y_UNUSED(result_listener); const auto& state = TProbableTraits::ExtractState(arg); return 0 == state.MoveConstructors && 0 == state.MoveAssignments; } - + MATCHER(NoAssignments, "no assignments were made") { Y_UNUSED(result_listener); const auto& state = TProbableTraits::ExtractState(arg); return 0 == state.CopyAssignments && 0 == state.MoveAssignments; } -} +} diff --git a/library/cpp/yson/varint.h b/library/cpp/yson/varint.h index 80b1184e57..af46e23f53 100644 --- a/library/cpp/yson/varint.h +++ b/library/cpp/yson/varint.h @@ -1,24 +1,24 @@ -#pragma once - -#include <util/stream/input.h> -#include <util/stream/output.h> -#include <util/system/defaults.h> - +#pragma once + +#include <util/stream/input.h> +#include <util/stream/output.h> +#include <util/system/defaults.h> + namespace NYson { //////////////////////////////////////////////////////////////////////////////// - + // Various functions that read/write varints from/to a stream. - + // Returns the number of bytes written. int WriteVarUInt64(IOutputStream* output, ui64 value); int WriteVarInt32(IOutputStream* output, i32 value); int WriteVarInt64(IOutputStream* output, i64 value); - + // Returns the number of bytes read. int ReadVarUInt64(IInputStream* input, ui64* value); int ReadVarInt32(IInputStream* input, i32* value); int ReadVarInt64(IInputStream* input, i64* value); - + //////////////////////////////////////////////////////////////////////////////// - + } // namespace NYson diff --git a/library/cpp/yt/coding/varint.h b/library/cpp/yt/coding/varint.h index c5399f8b06..b3b51056cd 100644 --- a/library/cpp/yt/coding/varint.h +++ b/library/cpp/yt/coding/varint.h @@ -1,55 +1,55 @@ -#pragma once - +#pragma once + #include <library/cpp/yt/exception/exception.h> -#include <util/system/defaults.h> - +#include <util/system/defaults.h> + #include <util/stream/input.h> #include <util/stream/output.h> - -namespace NYT { - -//////////////////////////////////////////////////////////////////////////////// - + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + constexpr size_t MaxVarInt64Size = (8 * sizeof(ui64) - 1) / 7 + 1; constexpr size_t MaxVarUint64Size = (8 * sizeof(ui64) - 1) / 7 + 1; - + constexpr size_t MaxVarInt32Size = (8 * sizeof(ui32) - 1) / 7 + 1; constexpr size_t MaxVarUint32Size = (8 * sizeof(ui32) - 1) / 7 + 1; // Various functions to read/write varints. - -// Returns the number of bytes written. + +// Returns the number of bytes written. int WriteVarUint64(IOutputStream* output, ui64 value); int WriteVarUint32(IOutputStream* output, ui32 value); int WriteVarInt32(IOutputStream* output, i32 value); int WriteVarInt64(IOutputStream* output, i64 value); - + int WriteVarUint64(char* output, ui64 value); int WriteVarUint32(char* output, ui32 value); int WriteVarInt32(char* output, i32 value); int WriteVarInt64(char* output, i64 value); - -// Returns the number of bytes read. + +// Returns the number of bytes read. int ReadVarUint64(IInputStream* input, ui64* value); int ReadVarUint32(IInputStream* input, ui32* value); int ReadVarInt32(IInputStream* input, i32* value); int ReadVarInt64(IInputStream* input, i64* value); - + int ReadVarUint64(const char* input, ui64* value); int ReadVarUint32(const char* input, ui32* value); int ReadVarInt32(const char* input, i32* value); int ReadVarInt64(const char* input, i64* value); - + // Throws exception if integer is not complete when `end' is reached. int ReadVarUint64(const char* input, const char* end, ui64* value); int ReadVarUint32(const char* input, const char* end, ui32* value); int ReadVarInt32(const char* input, const char* end, i32* value); int ReadVarInt64(const char* input, const char* end, i64* value); -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT #define VARINT_INL_H_ #include "varint-inl.h" diff --git a/library/cpp/yt/memory/intrusive_ptr.h b/library/cpp/yt/memory/intrusive_ptr.h index 3dead7db1d..74d1482854 100644 --- a/library/cpp/yt/memory/intrusive_ptr.h +++ b/library/cpp/yt/memory/intrusive_ptr.h @@ -99,7 +99,7 @@ public: template <class U> TIntrusivePtr& operator=(const TIntrusivePtr<U>& other) noexcept { - static_assert( + static_assert( std::is_convertible_v<U*, T*>, "U* must be convertible to T*"); static_assert( @@ -112,7 +112,7 @@ public: //! Move assignment operator. TIntrusivePtr& operator=(TIntrusivePtr&& other) noexcept { - TIntrusivePtr(std::move(other)).Swap(*this); + TIntrusivePtr(std::move(other)).Swap(*this); return *this; } @@ -120,13 +120,13 @@ public: template <class U> TIntrusivePtr& operator=(TIntrusivePtr<U>&& other) noexcept { - static_assert( + static_assert( std::is_convertible_v<U*, T*>, "U* must be convertible to T*"); static_assert( std::is_base_of_v<TRefCountedBase, T>, "Cast allowed only for types derived from TRefCountedBase"); - TIntrusivePtr(std::move(other)).Swap(*this); + TIntrusivePtr(std::move(other)).Swap(*this); return *this; } @@ -270,7 +270,7 @@ bool operator>(const TIntrusivePtr<T>& lhs, const TIntrusivePtr<T>& rhs) template <class T, class U> bool operator==(const TIntrusivePtr<T>& lhs, const TIntrusivePtr<U>& rhs) { - static_assert( + static_assert( std::is_convertible_v<U*, T*>, "U* must be convertible to T*"); return lhs.Get() == rhs.Get(); @@ -279,7 +279,7 @@ bool operator==(const TIntrusivePtr<T>& lhs, const TIntrusivePtr<U>& rhs) template <class T, class U> bool operator!=(const TIntrusivePtr<T>& lhs, const TIntrusivePtr<U>& rhs) { - static_assert( + static_assert( std::is_convertible_v<U*, T*>, "U* must be convertible to T*"); return lhs.Get() != rhs.Get(); @@ -288,7 +288,7 @@ bool operator!=(const TIntrusivePtr<T>& lhs, const TIntrusivePtr<U>& rhs) template <class T, class U> bool operator==(const TIntrusivePtr<T>& lhs, U* rhs) { - static_assert( + static_assert( std::is_convertible_v<U*, T*>, "U* must be convertible to T*"); return lhs.Get() == rhs; @@ -297,7 +297,7 @@ bool operator==(const TIntrusivePtr<T>& lhs, U* rhs) template <class T, class U> bool operator!=(const TIntrusivePtr<T>& lhs, U* rhs) { - static_assert( + static_assert( std::is_convertible_v<U*, T*>, "U* must be convertible to T*"); return lhs.Get() != rhs; @@ -306,7 +306,7 @@ bool operator!=(const TIntrusivePtr<T>& lhs, U* rhs) template <class T, class U> bool operator==(T* lhs, const TIntrusivePtr<U>& rhs) { - static_assert( + static_assert( std::is_convertible_v<U*, T*>, "U* must be convertible to T*"); return lhs == rhs.Get(); @@ -315,7 +315,7 @@ bool operator==(T* lhs, const TIntrusivePtr<U>& rhs) template <class T, class U> bool operator!=(T* lhs, const TIntrusivePtr<U>& rhs) { - static_assert( + static_assert( std::is_convertible_v<U*, T*>, "U* must be convertible to T*"); return lhs != rhs.Get(); diff --git a/library/cpp/yt/memory/ref.h b/library/cpp/yt/memory/ref.h index 73d19d9013..31d171cf0d 100644 --- a/library/cpp/yt/memory/ref.h +++ b/library/cpp/yt/memory/ref.h @@ -307,8 +307,8 @@ private: const TSharedRef* begin(const TSharedRefArray& array); const TSharedRef* end(const TSharedRefArray& array); -//////////////////////////////////////////////////////////////////////////////// - +//////////////////////////////////////////////////////////////////////////////// + struct TDefaultSharedRefArrayBuilderTag { }; //! A helper for creating TSharedRefArray. diff --git a/library/cpp/yt/memory/ref_tracked.h b/library/cpp/yt/memory/ref_tracked.h index 75c1eb5985..608c1bbe3a 100644 --- a/library/cpp/yt/memory/ref_tracked.h +++ b/library/cpp/yt/memory/ref_tracked.h @@ -1,17 +1,17 @@ -#pragma once - +#pragma once + #include <library/cpp/yt/misc/port.h> #include <library/cpp/yt/misc/source_location.h> - + #include <util/system/defaults.h> #include <atomic> #include <typeinfo> -namespace NYT { - -//////////////////////////////////////////////////////////////////////////////// - +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + using TRefCountedTypeCookie = int; const int NullRefCountedTypeCookie = -1; @@ -64,24 +64,24 @@ TRefCountedTypeCookie GetRefCountedTypeCookieWithLocation( //////////////////////////////////////////////////////////////////////////////// -//! A lightweight mix-in that integrates any class into TRefCountedTracker statistics. -/*! - * |T| must be the actual derived type. +//! A lightweight mix-in that integrates any class into TRefCountedTracker statistics. +/*! + * |T| must be the actual derived type. * - * This mix-in provides statistical tracking only, |T| is responsible for implementing - * lifetime management on its own. - */ -template <class T> -class TRefTracked -{ -public: + * This mix-in provides statistical tracking only, |T| is responsible for implementing + * lifetime management on its own. + */ +template <class T> +class TRefTracked +{ +public: #ifdef YT_ENABLE_REF_COUNTED_TRACKING - TRefTracked() - { + TRefTracked() + { auto cookie = GetRefCountedTypeCookie<T>(); TRefCountedTrackerFacade::AllocateInstance(cookie); - } - + } + TRefTracked(const TRefTracked&) { auto cookie = GetRefCountedTypeCookie<T>(); @@ -94,17 +94,17 @@ public: TRefCountedTrackerFacade::AllocateInstance(cookie); } - ~TRefTracked() - { + ~TRefTracked() + { auto cookie = GetRefCountedTypeCookie<T>(); TRefCountedTrackerFacade::FreeInstance(cookie); } -#endif -}; - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT +#endif +}; + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT #define REF_TRACKED_INL_H_ #include "ref_tracked-inl.h" diff --git a/library/cpp/yt/memory/weak_ptr.h b/library/cpp/yt/memory/weak_ptr.h index 25a242bb8a..ef6de44546 100644 --- a/library/cpp/yt/memory/weak_ptr.h +++ b/library/cpp/yt/memory/weak_ptr.h @@ -102,7 +102,7 @@ public: template <class U> TWeakPtr& operator=(const TIntrusivePtr<U>& ptr) noexcept { - static_assert( + static_assert( std::is_convertible_v<U*, T*>, "U* must be convertible to T*"); TWeakPtr(ptr).Swap(*this); @@ -120,7 +120,7 @@ public: template <class U> TWeakPtr& operator=(const TWeakPtr<U>& other) noexcept { - static_assert( + static_assert( std::is_convertible_v<U*, T*>, "U* must be convertible to T*"); TWeakPtr(other).Swap(*this); @@ -141,7 +141,7 @@ public: static_assert( std::is_convertible_v<U*, T*>, "U* must be convertible to T*"); - TWeakPtr(std::move(other)).Swap(*this); + TWeakPtr(std::move(other)).Swap(*this); return *this; } @@ -161,7 +161,7 @@ public: template <class U> void Reset(const TIntrusivePtr<U>& ptr) // noexcept { - static_assert( + static_assert( std::is_convertible_v<U*, T*>, "U* must be convertible to T*"); TWeakPtr(ptr).Swap(*this); @@ -267,7 +267,7 @@ int ResetAndGetResidualRefCount(TIntrusivePtr<T>& pointer) //////////////////////////////////////////////////////////////////////////////// -// TODO(sandello): Kill comparsions. +// TODO(sandello): Kill comparsions. template <class T> bool operator<(const TWeakPtr<T>& lhs, const TWeakPtr<T>& rhs) { @@ -283,7 +283,7 @@ bool operator>(const TWeakPtr<T>& lhs, const TWeakPtr<T>& rhs) template <class T, class U> bool operator==(const TWeakPtr<T>& lhs, const TWeakPtr<U>& rhs) { - static_assert( + static_assert( std::is_convertible_v<U*, T*>, "U* must be convertible to T*"); return lhs.Lock().Get() == rhs.Lock().Get(); @@ -292,7 +292,7 @@ bool operator==(const TWeakPtr<T>& lhs, const TWeakPtr<U>& rhs) template <class T, class U> bool operator!=(const TWeakPtr<T>& lhs, const TWeakPtr<U>& rhs) { - static_assert( + static_assert( std::is_convertible_v<U*, T*>, "U* must be convertible to T*"); return lhs.Lock().Get() != rhs.Lock().Get(); diff --git a/library/cpp/yt/small_containers/compact_set.h b/library/cpp/yt/small_containers/compact_set.h index 2ca8713ea7..bab360420e 100644 --- a/library/cpp/yt/small_containers/compact_set.h +++ b/library/cpp/yt/small_containers/compact_set.h @@ -1,34 +1,34 @@ //===- llvm/ADT/SmallSet.h - 'Normally small' sets --------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// // This file defines the TCompactSet class. -// -//===----------------------------------------------------------------------===// - -#pragma once - +// +//===----------------------------------------------------------------------===// + +#pragma once + #include "compact_vector.h" - + #include <util/system/yassert.h> #include <cstddef> #include <iterator> -#include <set> +#include <set> #include <type_traits> - -namespace NYT { - + +namespace NYT { + /// TCompactSet - This maintains a set of unique values, optimizing for the case -/// when the set is small (less than N). In this case, the set can be -/// maintained with no mallocs. If the set gets large, we expand to using an -/// std::set to maintain reasonable lookup times. -/// +/// when the set is small (less than N). In this case, the set can be +/// maintained with no mallocs. If the set gets large, we expand to using an +/// std::set to maintain reasonable lookup times. +/// /// Note that any modification of the set may invalidate *all* iterators. template <typename T, unsigned N, typename C = std::less<T>> class TCompactSet @@ -43,29 +43,29 @@ private: using TSetConstIterator = typename std::set<T, C>::const_iterator; using TVectorConstIterator = typename TCompactVector<T, N>::const_iterator; -public: +public: class const_iterator; using size_type = std::size_t; - + TCompactSet() {} - + [[nodiscard]] bool empty() const; size_type size() const; - + const T& front() const; - + /// count - Return true if the element is in the set. size_type count(const T& v) const; - + /// insert - Insert an element into the set if it isn't already there. std::pair<const_iterator, bool> insert(const T& v); - + template <typename TIter> void insert(TIter i, TIter e); - + bool erase(const T& v); - + void clear(); const_iterator begin() const; @@ -74,11 +74,11 @@ public: const_iterator end() const; const_iterator cend() const; -private: +private: bool IsSmall() const; -}; - -} // namespace NYT +}; + +} // namespace NYT #define COMPACT_SET_INL_H_ #include "compact_set-inl.h" |