diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2023-06-30 17:09:50 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2023-06-30 17:09:50 +0300 |
commit | 97664d8dda87c01b255d33055b33d1209de5e0fe (patch) | |
tree | ff316dd506766884405213d585fa0097167bc1ad /library | |
parent | d4d31d3a7786d8351e5abd7227013217df3895b3 (diff) | |
download | ydb-97664d8dda87c01b255d33055b33d1209de5e0fe.tar.gz |
Intermediate changes
Diffstat (limited to 'library')
-rw-r--r-- | library/cpp/neh/http_common.h | 4 | ||||
-rw-r--r-- | library/cpp/yt/memory/unittests/weak_ptr_ut.cpp | 7 | ||||
-rw-r--r-- | library/cpp/yt/memory/weak_ptr.h | 48 |
3 files changed, 43 insertions, 16 deletions
diff --git a/library/cpp/neh/http_common.h b/library/cpp/neh/http_common.h index d19d1e4522..69659ba907 100644 --- a/library/cpp/neh/http_common.h +++ b/library/cpp/neh/http_common.h @@ -147,7 +147,7 @@ namespace NNeh { } TVector<char> Mem; - + TString Data; private: TParts Parts_; }; @@ -215,6 +215,7 @@ namespace NNeh { req->AddPart(req->Mem.data(), out.Buf() - req->Mem.data()); req->AddPart(msg.Data.data(), msg.Data.size()); + req->Data = msg.Data; return req; } @@ -231,6 +232,7 @@ namespace NNeh { static TRequestData::TPtr Build(const TMessage& msg, const TParsedLocation&) { TRequestData::TPtr req(new TRequestData(0)); req->AddPart(msg.Data.data(), msg.Data.size()); + req->Data = msg.Data; return req; } diff --git a/library/cpp/yt/memory/unittests/weak_ptr_ut.cpp b/library/cpp/yt/memory/unittests/weak_ptr_ut.cpp index 180c16b5ca..6359d0bd66 100644 --- a/library/cpp/yt/memory/unittests/weak_ptr_ut.cpp +++ b/library/cpp/yt/memory/unittests/weak_ptr_ut.cpp @@ -300,6 +300,13 @@ TEST_F(TWeakPtrTest, IsExpired) EXPECT_TRUE(ptr.IsExpired()); } +TEST_F(TWeakPtrTest, IsEmpty) +{ + TIntricateObjectWkPtr ptr; + + EXPECT_TRUE(ptr == nullptr); +} + TEST_F(TWeakPtrTest, UpCast) { TDerivedIntricateObjectPtr object = New<TDerivedIntricateObject>(); diff --git a/library/cpp/yt/memory/weak_ptr.h b/library/cpp/yt/memory/weak_ptr.h index 57d174f510..6d2c5f0c01 100644 --- a/library/cpp/yt/memory/weak_ptr.h +++ b/library/cpp/yt/memory/weak_ptr.h @@ -189,6 +189,13 @@ public: return !T_ || (RefCounter()->GetRefCount() == 0); } + const TRefCounter* TryGetRefCounter() const + { + return T_ + ? RefCounter() + : nullptr; + } + private: void AcquireRef() { @@ -268,26 +275,13 @@ int ResetAndGetResidualRefCount(TIntrusivePtr<T>& pointer) //////////////////////////////////////////////////////////////////////////////// -// TODO(sandello): Kill comparisons. -template <class T> -bool operator<(const TWeakPtr<T>& lhs, const TWeakPtr<T>& rhs) -{ - return lhs.Lock().Get() < rhs.Lock().Get(); -} - -template <class T> -bool operator>(const TWeakPtr<T>& lhs, const TWeakPtr<T>& rhs) -{ - return lhs.Lock().Get() > rhs.Lock().Get(); -} - template <class T, class U> bool operator==(const TWeakPtr<T>& lhs, const TWeakPtr<U>& rhs) { static_assert( std::is_convertible_v<U*, T*>, "U* must be convertible to T*"); - return lhs.Lock().Get() == rhs.Lock().Get(); + return lhs.TryGetRefCounter() == rhs.TryGetRefCounter(); } template <class T, class U> @@ -296,7 +290,31 @@ bool operator!=(const TWeakPtr<T>& lhs, const TWeakPtr<U>& rhs) static_assert( std::is_convertible_v<U*, T*>, "U* must be convertible to T*"); - return lhs.Lock().Get() != rhs.Lock().Get(); + return lhs.TryGetRefCounter() != rhs.TryGetRefCounter(); +} + +template <class T> +bool operator==(std::nullptr_t, const TWeakPtr<T>& rhs) +{ + return nullptr == rhs.TryGetRefCounter(); +} + +template <class T> +bool operator!=(std::nullptr_t, const TWeakPtr<T>& rhs) +{ + return nullptr != rhs.TryGetRefCounter(); +} + +template <class T> +bool operator==(const TWeakPtr<T>& lhs, std::nullptr_t) +{ + return nullptr == lhs.TryGetRefCounter(); +} + +template <class T> +bool operator!=(const TWeakPtr<T>& lhs, std::nullptr_t) +{ + return nullptr != lhs.TryGetRefCounter(); } //////////////////////////////////////////////////////////////////////////////// |