From 6669fb735a600d7132400eaba3a07d1407c1fecc Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Thu, 11 Jul 2024 15:32:53 +0300 Subject: [PATCH 01/20] TAutoPtr -> std::unique_ptr in http.cpp --- src/library/http/server/http.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/library/http/server/http.cpp b/src/library/http/server/http.cpp index 528c348025..2a00049538 100644 --- a/src/library/http/server/http.cpp +++ b/src/library/http/server/http.cpp @@ -19,6 +19,7 @@ #include #include +#include #include using namespace NAddr; @@ -169,10 +170,10 @@ class THttpServer::TImpl { const THttpServerOptions& Options; }; - TAutoPtr CreateRequest(TAutoPtr c) { - THolder obj(Cb_->CreateClient()); + std::unique_ptr CreateRequest(std::unique_ptr& c) { + std::unique_ptr obj(Cb_->CreateClient()); - obj->Conn_.Reset(c.Release()); + obj->Conn_.Reset(c.release()); return obj; } @@ -287,9 +288,9 @@ class THttpServer::TImpl { // ignore result } - void AddRequest(TAutoPtr req, bool fail) { + void AddRequest(std::unique_ptr& req, bool fail) { struct TFailRequest: public THttpClientRequestEx { - inline TFailRequest(TAutoPtr parent) { + inline TFailRequest(std::unique_ptr& parent) { Conn_.Reset(parent->Conn_.Release()); HttpConn_.Reset(parent->HttpConn_.Release()); } @@ -304,13 +305,13 @@ class THttpServer::TImpl { } }; - if (!fail && Requests->Add(req.Get())) { - Y_UNUSED(req.Release()); + if (!fail && Requests->Add(req.get())) { + Y_UNUSED(req.release()); } else { - req = new TFailRequest(req); + req = std::make_unique(req); - if (FailRequests->Add(req.Get())) { - Y_UNUSED(req.Release()); + if (FailRequests->Add(req.get())) { + Y_UNUSED(req.release()); } else { Cb_->OnFailRequest(-1); } @@ -620,7 +621,7 @@ void TClientConnection::ScheduleDelete() { } void TClientConnection::OnPollEvent(TInstant now) { - THolder this_(this); + std::unique_ptr this_(this); Activate(now); { @@ -637,7 +638,7 @@ void TClientConnection::OnPollEvent(TInstant now) { } } - THolder obj(HttpServ_->CreateRequest(this_)); + std::unique_ptr obj = std::move(HttpServ_->CreateRequest(this_)); AcceptMoment = now; HttpServ_->AddRequest(obj, Reject_); From b71750b227b6491873fc8ea4eebfb8dcb448f189 Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Thu, 11 Jul 2024 15:38:58 +0300 Subject: [PATCH 02/20] TAutoPtr -> std::unique_ptr in utmain.cpp --- src/library/testing/unittest/utmain.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/library/testing/unittest/utmain.cpp b/src/library/testing/unittest/utmain.cpp index 376682f412..cfdbd72af5 100644 --- a/src/library/testing/unittest/utmain.cpp +++ b/src/library/testing/unittest/utmain.cpp @@ -129,11 +129,11 @@ class TTraceWriterProcessor: public ITestSuiteProcessor { inline TTraceWriterProcessor(const char* traceFilePath, EOpenMode mode) : PrevTime(TInstant::Now()) { - TraceFile = new TUnbufferedFileOutput(TFile(traceFilePath, mode | WrOnly | Seq)); + TraceFile = std::make_unique(TFile(traceFilePath, mode | WrOnly | Seq)); } private: - TAutoPtr TraceFile; + std::unique_ptr TraceFile; std::string TraceFilePath; TInstant PrevTime; std::vector ErrorMessages; @@ -148,7 +148,7 @@ class TTraceWriterProcessor: public ITestSuiteProcessor { json.EndObject(); - json.FlushTo(TraceFile.Get()); + json.FlushTo(TraceFile.get()); *TraceFile << "\n"; } From b9f44b0e63269a6271e76e2fb6bac51545254b7f Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Thu, 11 Jul 2024 15:42:17 +0300 Subject: [PATCH 03/20] TAutoPtr -> std::unique_ptr in gtest.cpp --- src/library/testing/unittest/gtest.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/library/testing/unittest/gtest.cpp b/src/library/testing/unittest/gtest.cpp index 1fb11bb494..404a771c71 100644 --- a/src/library/testing/unittest/gtest.cpp +++ b/src/library/testing/unittest/gtest.cpp @@ -3,6 +3,8 @@ #include +#include + using namespace NUnitTest; using namespace NUnitTest::NPrivate; @@ -53,13 +55,13 @@ namespace { } IGTestFactory* NUnitTest::NPrivate::ByName(const char* name) { - static std::map> tests; + static std::map> tests; auto& ret = tests[name]; if (!ret) { - ret = new TGTestFactory(name); + ret = std::make_unique(name); } - return ret.Get(); + return ret.get(); } From ed8dddbed847601b8bbebf6f6de9f44150446b28 Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Thu, 11 Jul 2024 15:54:00 +0300 Subject: [PATCH 04/20] TAutoPtr -> std::unique_ptr in lz.h --- src/library/streams/lz/lz.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/library/streams/lz/lz.h b/src/library/streams/lz/lz.h index 10be1da270..ec87b72b95 100644 --- a/src/library/streams/lz/lz.h +++ b/src/library/streams/lz/lz.h @@ -10,6 +10,8 @@ #include #include +#include + /** * @file * @@ -159,10 +161,10 @@ class TLzqDecompress: public IInputStream { * @param input Stream to decompress. * @return Decompressing proxy input stream. */ -TAutoPtr OpenLzDecompressor(IInputStream* input); -TAutoPtr TryOpenLzDecompressor(IInputStream* input); -TAutoPtr TryOpenLzDecompressor(const std::string_view& signature, IInputStream* input); +std::unique_ptr OpenLzDecompressor(IInputStream* input); +std::unique_ptr TryOpenLzDecompressor(IInputStream* input); +std::unique_ptr TryOpenLzDecompressor(const std::string_view& signature, IInputStream* input); -TAutoPtr OpenOwnedLzDecompressor(TAutoPtr input); -TAutoPtr TryOpenOwnedLzDecompressor(TAutoPtr input); -TAutoPtr TryOpenOwnedLzDecompressor(const std::string_view& signature, TAutoPtr input); +std::unique_ptr OpenOwnedLzDecompressor(std::unique_ptr input); +std::unique_ptr TryOpenOwnedLzDecompressor(std::unique_ptr input); +std::unique_ptr TryOpenOwnedLzDecompressor(const std::string_view& signature, std::unique_ptr input); From 1161ed6b879c8b663fc2e5f784099277077403d5 Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Thu, 11 Jul 2024 15:58:47 +0300 Subject: [PATCH 05/20] TAutoPtr -> std::unique_ptr in last_getopt_opt.h --- src/library/getopt/small/last_getopt_opt.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/library/getopt/small/last_getopt_opt.h b/src/library/getopt/small/last_getopt_opt.h index 848eccb2ed..792b6908e7 100644 --- a/src/library/getopt/small/last_getopt_opt.h +++ b/src/library/getopt/small/last_getopt_opt.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace NLastGetopt { enum EHasArg { @@ -607,13 +608,13 @@ namespace NLastGetopt { return Handler1(f); } - TOpt& Handler(TAutoPtr handler) { - return HandlerImpl(handler.Release()); + TOpt& Handler(std::unique_ptr& handler) { + return HandlerImpl(handler.release()); } template // T extends IOptHandler - TOpt& Handler(TAutoPtr handler) { - return HandlerImpl(handler.Release()); + TOpt& Handler(std::unique_ptr& handler) { + return HandlerImpl(handler.release()); } // Stores FromString(arg) in *target From aeb41530f7e0775ca473683873d5f778df20d9f6 Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Thu, 11 Jul 2024 16:01:56 +0300 Subject: [PATCH 06/20] TAutoPtr -> std::unique_ptr in equeue_ut.cpp --- src/library/threading/equeue/equeue_ut.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/library/threading/equeue/equeue_ut.cpp b/src/library/threading/equeue/equeue_ut.cpp index 6ebe27c244..4853163784 100644 --- a/src/library/threading/equeue/equeue_ut.cpp +++ b/src/library/threading/equeue/equeue_ut.cpp @@ -6,6 +6,7 @@ #include #include +#include Y_UNIT_TEST_SUITE(TElasticQueueTest) { const size_t MaxQueueSize = 20; @@ -139,7 +140,7 @@ Y_UNIT_TEST_SUITE(TElasticQueueTest) { { typename TEnv::TQueueSetup setup; - std::vector< TAutoPtr > senders; + std::vector< std::unique_ptr > senders; for (size_t i = 0; i < ThreadCount; ++i) { senders.push_back(::SystemThreadFactory()->Run(&sender)); } From 5eb6b2a2b9a8560ab139a9b753938e0a9a72b1a9 Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Thu, 11 Jul 2024 16:05:10 +0300 Subject: [PATCH 07/20] TAutoPtr -> std::unique_ptr in queue.h --- src/library/threading/chunk_queue/queue.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/library/threading/chunk_queue/queue.h b/src/library/threading/chunk_queue/queue.h index 3e5c74bff3..9bf7b335cf 100644 --- a/src/library/threading/chunk_queue/queue.h +++ b/src/library/threading/chunk_queue/queue.h @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -522,21 +523,21 @@ namespace NThreading { TImpl Impl; public: - using TItem = TAutoPtr; + using TItem = std::unique_ptr; ~TAutoQueueBase() { - TAutoPtr value; + std::unique_ptr value; while (Dequeue(value)) { // do nothing } } - void Enqueue(TAutoPtr value) { + void Enqueue(std::unique_ptr value) { Impl.Enqueue(value.Get()); Y_UNUSED(value.Release()); } - bool Dequeue(TAutoPtr& value) { + bool Dequeue(std::unique_ptr& value) { T* ptr = nullptr; if (Impl.Dequeue(ptr)) { value.Reset(ptr); From bffd9d9e96219c9c963f49d6effcb199f7e16218 Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Thu, 11 Jul 2024 16:21:09 +0300 Subject: [PATCH 08/20] TAutoPtr -> std::unique_ptr in thread_helper.h --- include/ydb-cpp-sdk/util/thread/pool.h | 5 +++-- src/library/threading/poor_man_openmp/thread_helper.h | 4 ++-- src/util/thread/pool.cpp | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/ydb-cpp-sdk/util/thread/pool.h b/include/ydb-cpp-sdk/util/thread/pool.h index 1e83d8e6ee..e37b83194f 100644 --- a/include/ydb-cpp-sdk/util/thread/pool.h +++ b/include/ydb-cpp-sdk/util/thread/pool.h @@ -8,6 +8,7 @@ #include #include +#include class TDuration; @@ -15,7 +16,7 @@ struct IObjectInQueue { virtual ~IObjectInQueue() = default; /** - * Supposed to be implemented by user, to define jobs processed + * Supposed to be implemented by user, to define jobs pCrocessed * in multiple threads. * * @param threadSpecificResource is nullptr by default. But if you override @@ -386,4 +387,4 @@ inline void Delete(THolder q) { * Creates and starts TThreadPool if threadsCount > 1, or TFakeThreadPool otherwise * You could specify blocking and catching modes for TThreadPool only */ -THolder CreateThreadPool(size_t threadCount, size_t queueSizeLimit = 0, const IThreadPool::TParams& params = {}); +std::unique_ptr CreateThreadPool(size_t threadCount, size_t queueSizeLimit = 0, const IThreadPool::TParams& params = {}); diff --git a/src/library/threading/poor_man_openmp/thread_helper.h b/src/library/threading/poor_man_openmp/thread_helper.h index f0bb5cccbe..6ea6f484f4 100644 --- a/src/library/threading/poor_man_openmp/thread_helper.h +++ b/src/library/threading/poor_man_openmp/thread_helper.h @@ -18,7 +18,7 @@ class TMtpQueueHelper { SetThreadCount(NSystemInfo::CachedNumberOfCpus()); } IThreadPool* Get() { - return q.Get(); + return q.get(); } size_t GetThreadCount() { return ThreadCount; @@ -32,7 +32,7 @@ class TMtpQueueHelper { private: size_t ThreadCount; - TAutoPtr q; + std::unique_ptr q; }; namespace NYmp { diff --git a/src/util/thread/pool.cpp b/src/util/thread/pool.cpp index 8723593796..734947f8ee 100644 --- a/src/util/thread/pool.cpp +++ b/src/util/thread/pool.cpp @@ -767,12 +767,12 @@ IThread* IThreadPool::DoCreate() { return new TPoolThread(this); } -THolder CreateThreadPool(size_t threadsCount, size_t queueSizeLimit, const TThreadPoolParams& params) { - THolder queue; +std::unique_ptr CreateThreadPool(size_t threadsCount, size_t queueSizeLimit, const TThreadPoolParams& params) { + std::unique_ptr queue; if (threadsCount > 1) { - queue.Reset(new TThreadPool(params)); + queue.reset(new TThreadPool(params)); } else { - queue.Reset(new TFakeThreadPool()); + queue.reset(new TFakeThreadPool()); } queue->Start(threadsCount, queueSizeLimit); return queue; From b4ca3a18fbe3f8a66ee7bd73c2b7e619aff6afd2 Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Thu, 11 Jul 2024 16:23:36 +0300 Subject: [PATCH 09/20] TAutoPtr -> std::unique_ptr in init.cpp --- src/library/openssl/init/init.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/library/openssl/init/init.cpp b/src/library/openssl/init/init.cpp index 2395720e83..9c3aaa723b 100644 --- a/src/library/openssl/init/init.cpp +++ b/src/library/openssl/init/init.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include namespace { @@ -27,7 +28,7 @@ namespace { : Mutexes(CRYPTO_num_locks()) { for (auto& mpref : Mutexes) { - mpref.Reset(new std::mutex()); + mpref.reset(new std::mutex()); } } @@ -41,7 +42,7 @@ namespace { } } - std::vector> Mutexes; + std::vector> Mutexes; }; inline TInitSsl() { From 2798964e7308a7abb2ee3ed84878d36794174fe4 Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Thu, 11 Jul 2024 16:36:20 +0300 Subject: [PATCH 10/20] TAutoPtr -> std::unique_ptr in dumpers.h --- src/library/dbg_output/dumpers.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/library/dbg_output/dumpers.h b/src/library/dbg_output/dumpers.h index bf9e410ed6..93fd543d41 100644 --- a/src/library/dbg_output/dumpers.h +++ b/src/library/dbg_output/dumpers.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -15,10 +16,10 @@ //smart pointers template -struct TDumper> { +struct TDumper> { template - static inline void Dump(S& s, const TAutoPtr& v) { - s << DumpRaw("TAutoPtr(") << v.Get() << DumpRaw(")"); + static inline void Dump(S& s, const std::unique_ptr& v) { + s << DumpRaw("std::unique_ptr(") << v.get() << DumpRaw(")"); } }; From e9abb359917972d0e54871e973faf129c5d2486b Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Thu, 11 Jul 2024 16:40:31 +0300 Subject: [PATCH 11/20] TAutoPtr -> std::unique_ptr in ptr_ut.cpp --- src/util/generic/ptr_ut.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/util/generic/ptr_ut.cpp b/src/util/generic/ptr_ut.cpp index be8a95d4c7..cf51494069 100644 --- a/src/util/generic/ptr_ut.cpp +++ b/src/util/generic/ptr_ut.cpp @@ -242,8 +242,8 @@ void TPointerTest::TestMakeHolder() { void TPointerTest::TestTrulePtr() { { - TAutoPtr a1(MakeA()); - TAutoPtr a2(a1); + std::unique_ptr a1(MakeA()); + std::unique_ptr a2(a1); a1 = a2; } @@ -252,8 +252,8 @@ void TPointerTest::TestTrulePtr() { void TPointerTest::TestAutoToHolder() { { - TAutoPtr a1(MakeA()); - THolder a2(a1); + std::unique_ptr a1(MakeA()); + std::unique_ptr a2(a1); UNIT_ASSERT_EQUAL(a1.Get(), nullptr); UNIT_ASSERT_VALUES_EQUAL(cnt, 1); @@ -262,8 +262,8 @@ void TPointerTest::TestAutoToHolder() { UNIT_ASSERT_VALUES_EQUAL(cnt, 0); { - TAutoPtr x(new A()); - THolder y = x; + std::unique_ptr x(new A()); + std::unique_ptr y = x; } UNIT_ASSERT_VALUES_EQUAL(cnt, 0); @@ -272,8 +272,8 @@ void TPointerTest::TestAutoToHolder() { class B1: public A { }; - TAutoPtr x(new B1()); - THolder y = x; + std::unique_ptr x(new B1()); + std::unique_ptr y = x; } UNIT_ASSERT_VALUES_EQUAL(cnt, 0); @@ -575,8 +575,8 @@ void TPointerTest::TestOperatorBool() { // pointers UNIT_ASSERT(!(TImplicitlyCastable, int>::Result)); - UNIT_ASSERT(!(TImplicitlyCastable, ui64>::Result)); - UNIT_ASSERT(!(TImplicitlyCastable, bool>::Result)); // even this + UNIT_ASSERT(!(TImplicitlyCastable, ui64>::Result)); + UNIT_ASSERT(!(TImplicitlyCastable, bool>::Result)); // even this { // mostly a compilability test @@ -719,8 +719,8 @@ void TestPtrComparison(const TPtr& ptr) { } void TPointerTest::TestComparison() { - THolder ptr1(new A); - TAutoPtr ptr2; + std::unique_ptr ptr1(new A); + std::unique_ptr ptr2; TSimpleSharedPtr ptr3(new int(6)); TIntrusivePtr ptr4; TIntrusiveConstPtr ptr5 = ptr4; From 7dae8b60af7dda31bc8849dcfcecdafdb5171002 Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Fri, 12 Jul 2024 10:45:07 +0300 Subject: [PATCH 12/20] The original comment in the code has been restored --- include/ydb-cpp-sdk/util/thread/pool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ydb-cpp-sdk/util/thread/pool.h b/include/ydb-cpp-sdk/util/thread/pool.h index e37b83194f..ce933a462c 100644 --- a/include/ydb-cpp-sdk/util/thread/pool.h +++ b/include/ydb-cpp-sdk/util/thread/pool.h @@ -16,7 +16,7 @@ struct IObjectInQueue { virtual ~IObjectInQueue() = default; /** - * Supposed to be implemented by user, to define jobs pCrocessed + * Supposed to be implemented by user, to define jobs processed * in multiple threads. * * @param threadSpecificResource is nullptr by default. But if you override From 252f8fbe6aacc0d1a56ee66db3ef05c3fa1543c2 Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Fri, 12 Jul 2024 13:32:03 +0300 Subject: [PATCH 13/20] Rollback ptr_ut.cpp to the previous state --- src/util/generic/ptr_ut.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/util/generic/ptr_ut.cpp b/src/util/generic/ptr_ut.cpp index cf51494069..eb2fe22f12 100644 --- a/src/util/generic/ptr_ut.cpp +++ b/src/util/generic/ptr_ut.cpp @@ -242,8 +242,8 @@ void TPointerTest::TestMakeHolder() { void TPointerTest::TestTrulePtr() { { - std::unique_ptr a1(MakeA()); - std::unique_ptr a2(a1); + TAutoPtr a1(MakeA()); + TAutoPtr a2(a1); a1 = a2; } @@ -252,8 +252,8 @@ void TPointerTest::TestTrulePtr() { void TPointerTest::TestAutoToHolder() { { - std::unique_ptr a1(MakeA()); - std::unique_ptr a2(a1); + TAutoPtr a1(MakeA()); + THolder a2(a1); UNIT_ASSERT_EQUAL(a1.Get(), nullptr); UNIT_ASSERT_VALUES_EQUAL(cnt, 1); @@ -262,8 +262,8 @@ void TPointerTest::TestAutoToHolder() { UNIT_ASSERT_VALUES_EQUAL(cnt, 0); { - std::unique_ptr x(new A()); - std::unique_ptr y = x; + TAutoPtr x(new A()); + THolder y = x; } UNIT_ASSERT_VALUES_EQUAL(cnt, 0); @@ -272,8 +272,8 @@ void TPointerTest::TestAutoToHolder() { class B1: public A { }; - std::unique_ptr x(new B1()); - std::unique_ptr y = x; + TAutoPtr x(new B1()); + THolder y = x; } UNIT_ASSERT_VALUES_EQUAL(cnt, 0); @@ -575,8 +575,8 @@ void TPointerTest::TestOperatorBool() { // pointers UNIT_ASSERT(!(TImplicitlyCastable, int>::Result)); - UNIT_ASSERT(!(TImplicitlyCastable, ui64>::Result)); - UNIT_ASSERT(!(TImplicitlyCastable, bool>::Result)); // even this + UNIT_ASSERT(!(TImplicitlyCastable, ui64>::Result)); + UNIT_ASSERT(!(TImplicitlyCastable, bool>::Result)); // even this { // mostly a compilability test @@ -719,8 +719,8 @@ void TestPtrComparison(const TPtr& ptr) { } void TPointerTest::TestComparison() { - std::unique_ptr ptr1(new A); - std::unique_ptr ptr2; + THolder ptr1(new A); + TAutoPtr ptr2; TSimpleSharedPtr ptr3(new int(6)); TIntrusivePtr ptr4; TIntrusiveConstPtr ptr5 = ptr4; @@ -932,4 +932,4 @@ void TPointerTest::TestSharedPtrDowncast() { UNIT_ASSERT_VALUES_EQUAL(probeState.Destructors, 1); } -} +} \ No newline at end of file From 05ff4502c192ba283a1734148ddd251367a02c3e Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Mon, 15 Jul 2024 18:16:08 +0300 Subject: [PATCH 14/20] rvalue arg in CreatRequest --- src/library/http/server/http.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/library/http/server/http.cpp b/src/library/http/server/http.cpp index 2a00049538..0f4ed582be 100644 --- a/src/library/http/server/http.cpp +++ b/src/library/http/server/http.cpp @@ -170,7 +170,7 @@ class THttpServer::TImpl { const THttpServerOptions& Options; }; - std::unique_ptr CreateRequest(std::unique_ptr& c) { + std::unique_ptr CreateRequest(std::unique_ptr&& c) { std::unique_ptr obj(Cb_->CreateClient()); obj->Conn_.Reset(c.release()); @@ -638,7 +638,7 @@ void TClientConnection::OnPollEvent(TInstant now) { } } - std::unique_ptr obj = std::move(HttpServ_->CreateRequest(this_)); + std::unique_ptr obj = HttpServ_->CreateRequest(std::move(this_)); AcceptMoment = now; HttpServ_->AddRequest(obj, Reject_); From 8662bd7e4ee1d0f32ba65e564d243c5e8033f285 Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Mon, 15 Jul 2024 18:22:40 +0300 Subject: [PATCH 15/20] replaced new with make_unique --- src/library/openssl/init/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library/openssl/init/init.cpp b/src/library/openssl/init/init.cpp index 9c3aaa723b..33cdf5d89e 100644 --- a/src/library/openssl/init/init.cpp +++ b/src/library/openssl/init/init.cpp @@ -28,7 +28,7 @@ namespace { : Mutexes(CRYPTO_num_locks()) { for (auto& mpref : Mutexes) { - mpref.reset(new std::mutex()); + mpref = std::make_unique(); } } From 04d5b8d81676cb0b3e74141dfd8fd92da1d17ae1 Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Mon, 15 Jul 2024 18:24:30 +0300 Subject: [PATCH 16/20] replaced the copy with an rvalue ref --- src/library/streams/lz/lz.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/library/streams/lz/lz.h b/src/library/streams/lz/lz.h index ec87b72b95..a5815f4134 100644 --- a/src/library/streams/lz/lz.h +++ b/src/library/streams/lz/lz.h @@ -165,6 +165,6 @@ std::unique_ptr OpenLzDecompressor(IInputStream* input); std::unique_ptr TryOpenLzDecompressor(IInputStream* input); std::unique_ptr TryOpenLzDecompressor(const std::string_view& signature, IInputStream* input); -std::unique_ptr OpenOwnedLzDecompressor(std::unique_ptr input); -std::unique_ptr TryOpenOwnedLzDecompressor(std::unique_ptr input); -std::unique_ptr TryOpenOwnedLzDecompressor(const std::string_view& signature, std::unique_ptr input); +std::unique_ptr OpenOwnedLzDecompressor(std::unique_ptr&& input); +std::unique_ptr TryOpenOwnedLzDecompressor(std::unique_ptr&& input); +std::unique_ptr TryOpenOwnedLzDecompressor(const std::string_view& signature, std::unique_ptr&& input); From a00a93fe452079d176471d6371ef100960f47d9c Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Mon, 15 Jul 2024 18:25:42 +0300 Subject: [PATCH 17/20] replaced the copy with an rvalue ref --- src/library/threading/chunk_queue/queue.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library/threading/chunk_queue/queue.h b/src/library/threading/chunk_queue/queue.h index 9bf7b335cf..aaa3fe4424 100644 --- a/src/library/threading/chunk_queue/queue.h +++ b/src/library/threading/chunk_queue/queue.h @@ -532,7 +532,7 @@ namespace NThreading { } } - void Enqueue(std::unique_ptr value) { + void Enqueue(std::unique_ptr&& value) { Impl.Enqueue(value.Get()); Y_UNUSED(value.Release()); } From d32b7ecd21677b36e92fa56437fd8301abc0a974 Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Mon, 15 Jul 2024 18:55:57 +0300 Subject: [PATCH 18/20] replaced reset with std::make_unique --- src/util/thread/pool.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/thread/pool.cpp b/src/util/thread/pool.cpp index 734947f8ee..96594436bf 100644 --- a/src/util/thread/pool.cpp +++ b/src/util/thread/pool.cpp @@ -770,9 +770,9 @@ IThread* IThreadPool::DoCreate() { std::unique_ptr CreateThreadPool(size_t threadsCount, size_t queueSizeLimit, const TThreadPoolParams& params) { std::unique_ptr queue; if (threadsCount > 1) { - queue.reset(new TThreadPool(params)); + queue = std::make_unique(params); } else { - queue.reset(new TFakeThreadPool()); + queue = std::make_unique(); } queue->Start(threadsCount, queueSizeLimit); return queue; From cae748ca159ca20d2c077d5cadbac6753752e045 Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Mon, 15 Jul 2024 18:59:26 +0300 Subject: [PATCH 19/20] removed the change in ptr_ut.cpp --- src/util/generic/ptr_ut.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/generic/ptr_ut.cpp b/src/util/generic/ptr_ut.cpp index eb2fe22f12..0f0bd2e424 100644 --- a/src/util/generic/ptr_ut.cpp +++ b/src/util/generic/ptr_ut.cpp @@ -931,5 +931,5 @@ void TPointerTest::TestSharedPtrDowncast() { } UNIT_ASSERT_VALUES_EQUAL(probeState.Destructors, 1); - } + } } \ No newline at end of file From 8f2228f808ac2196796a23794cccb380ad58ed64 Mon Sep 17 00:00:00 2001 From: st-shchetinin Date: Mon, 15 Jul 2024 20:22:21 +0300 Subject: [PATCH 20/20] rvalue refs in function arguments --- src/library/getopt/small/last_getopt_opt.h | 4 ++-- src/library/http/server/http.cpp | 8 ++++---- src/library/threading/chunk_queue/queue.h | 2 +- src/util/generic/ptr_ut.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/library/getopt/small/last_getopt_opt.h b/src/library/getopt/small/last_getopt_opt.h index 792b6908e7..74be6a1769 100644 --- a/src/library/getopt/small/last_getopt_opt.h +++ b/src/library/getopt/small/last_getopt_opt.h @@ -608,12 +608,12 @@ namespace NLastGetopt { return Handler1(f); } - TOpt& Handler(std::unique_ptr& handler) { + TOpt& Handler(std::unique_ptr&& handler) { return HandlerImpl(handler.release()); } template // T extends IOptHandler - TOpt& Handler(std::unique_ptr& handler) { + TOpt& Handler(std::unique_ptr&& handler) { return HandlerImpl(handler.release()); } diff --git a/src/library/http/server/http.cpp b/src/library/http/server/http.cpp index 0f4ed582be..6fb8292c27 100644 --- a/src/library/http/server/http.cpp +++ b/src/library/http/server/http.cpp @@ -288,9 +288,9 @@ class THttpServer::TImpl { // ignore result } - void AddRequest(std::unique_ptr& req, bool fail) { + void AddRequest(std::unique_ptr&& req, bool fail) { struct TFailRequest: public THttpClientRequestEx { - inline TFailRequest(std::unique_ptr& parent) { + inline TFailRequest(std::unique_ptr&& parent) { Conn_.Reset(parent->Conn_.Release()); HttpConn_.Reset(parent->HttpConn_.Release()); } @@ -308,7 +308,7 @@ class THttpServer::TImpl { if (!fail && Requests->Add(req.get())) { Y_UNUSED(req.release()); } else { - req = std::make_unique(req); + req = std::make_unique(std::move(req)); if (FailRequests->Add(req.get())) { Y_UNUSED(req.release()); @@ -641,7 +641,7 @@ void TClientConnection::OnPollEvent(TInstant now) { std::unique_ptr obj = HttpServ_->CreateRequest(std::move(this_)); AcceptMoment = now; - HttpServ_->AddRequest(obj, Reject_); + HttpServ_->AddRequest(std::move(obj), Reject_); } void TClientConnection::Activate(TInstant now) noexcept { diff --git a/src/library/threading/chunk_queue/queue.h b/src/library/threading/chunk_queue/queue.h index aaa3fe4424..893bcab399 100644 --- a/src/library/threading/chunk_queue/queue.h +++ b/src/library/threading/chunk_queue/queue.h @@ -537,7 +537,7 @@ namespace NThreading { Y_UNUSED(value.Release()); } - bool Dequeue(std::unique_ptr& value) { + bool Dequeue(std::unique_ptr&& value) { T* ptr = nullptr; if (Impl.Dequeue(ptr)) { value.Reset(ptr); diff --git a/src/util/generic/ptr_ut.cpp b/src/util/generic/ptr_ut.cpp index 0f0bd2e424..be8a95d4c7 100644 --- a/src/util/generic/ptr_ut.cpp +++ b/src/util/generic/ptr_ut.cpp @@ -931,5 +931,5 @@ void TPointerTest::TestSharedPtrDowncast() { } UNIT_ASSERT_VALUES_EQUAL(probeState.Destructors, 1); - } -} \ No newline at end of file + } +}