From 3b55e5e7a01a88c867787fe66a0675473e0c9e37 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 23 Oct 2024 16:13:59 +0800 Subject: [PATCH] Move construct `std::shared_ptr` objects --- src/alert_manager.cpp | 2 +- src/disk_buffer_pool.cpp | 2 +- src/file_view_pool.cpp | 2 +- src/mmap.cpp | 4 ++-- src/peer_connection.cpp | 2 +- src/torrent.cpp | 9 +++++---- src/tracker_manager.cpp | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/alert_manager.cpp b/src/alert_manager.cpp index 3836a3fd1c0..50429d29d64 100644 --- a/src/alert_manager.cpp +++ b/src/alert_manager.cpp @@ -103,7 +103,7 @@ namespace aux { #ifndef TORRENT_DISABLE_EXTENSIONS void alert_manager::add_extension(std::shared_ptr ext) { - m_ses_extensions.push_back(ext); + m_ses_extensions.push_back(std::move(ext)); } #endif diff --git a/src/disk_buffer_pool.cpp b/src/disk_buffer_pool.cpp index b904662de82..cdbae0e4947 100644 --- a/src/disk_buffer_pool.cpp +++ b/src/disk_buffer_pool.cpp @@ -127,7 +127,7 @@ namespace { if (m_exceeded_max_size) { exceeded = true; - if (o) m_observers.push_back(o); + if (o) m_observers.push_back(std::move(o)); } return ret; } diff --git a/src/file_view_pool.cpp b/src/file_view_pool.cpp index b56d33fb3a6..49de087821b 100644 --- a/src/file_view_pool.cpp +++ b/src/file_view_pool.cpp @@ -166,7 +166,7 @@ namespace libtorrent { namespace aux { { file_entry e = open_file_impl(p, file_index, fs, m, file_key #if TORRENT_HAVE_MAP_VIEW_OF_FILE - , open_unmap_lock + , std::move(open_unmap_lock) #endif ); diff --git a/src/mmap.cpp b/src/mmap.cpp index 6ee2e6a2519..b2dfbdaf08b 100644 --- a/src/mmap.cpp +++ b/src/mmap.cpp @@ -201,7 +201,7 @@ file_mapping::file_mapping(file_handle file, open_mode_t const mode, std::int64_ #endif ; if (advise != 0) - madvise(m_mapping, static_cast(m_size), advise); + ::madvise(m_mapping, static_cast(m_size), advise); } #endif } @@ -227,7 +227,7 @@ file_mapping::file_mapping(file_handle file, open_mode_t const mode , std::shared_ptr open_unmap_lock) : m_size(memory_map_size(mode, file_size, file)) , m_file(std::move(file), mode, m_size) - , m_open_unmap_lock(open_unmap_lock) + , m_open_unmap_lock(std::move(open_unmap_lock)) , m_mapping((mode & open_mode::no_mmap) ? nullptr : MapViewOfFile(m_file.handle(), map_access(mode), 0, 0, static_cast(m_size))) { diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 6f81a685378..d019088ff01 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -607,7 +607,7 @@ namespace libtorrent { void peer_connection::add_extension(std::shared_ptr ext) { TORRENT_ASSERT(is_single_thread()); - m_extensions.push_back(ext); + m_extensions.push_back(std::move(ext)); } peer_plugin const* peer_connection::find_plugin(string_view type) diff --git a/src/torrent.cpp b/src/torrent.cpp index 538e8963450..2bb03177040 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1480,19 +1480,20 @@ bool is_downloading_state(int const st) void torrent::add_extension(std::shared_ptr ext) { - m_extensions.push_back(ext); + m_extensions.push_back(std::move(ext)); + auto& ext_ref = m_extensions.back(); for (auto p : m_connections) { TORRENT_INCREMENT(m_iterating_connections); - std::shared_ptr pp(ext->new_connection(peer_connection_handle(p->self()))); + std::shared_ptr pp(ext_ref->new_connection(peer_connection_handle(p->self()))); if (pp) p->add_extension(std::move(pp)); } // if files are checked for this torrent, call the extension // to let it initialize itself if (m_connections_initialized) - ext->on_files_checked(); + ext_ref->on_files_checked(); } void torrent::remove_extension(std::shared_ptr ext) @@ -1508,7 +1509,7 @@ bool is_downloading_state(int const st) std::shared_ptr tp(ext(get_handle(), userdata)); if (!tp) return; - add_extension(tp); + add_extension(std::move(tp)); } #endif diff --git a/src/tracker_manager.cpp b/src/tracker_manager.cpp index 7c135da21b9..92180b67886 100644 --- a/src/tracker_manager.cpp +++ b/src/tracker_manager.cpp @@ -262,7 +262,7 @@ constexpr tracker_request_flags_t tracker_request::i2p; { TORRENT_ASSERT(is_single_thread()); m_udp_conns.erase(c->transaction_id()); - m_udp_conns[tid] = c; + m_udp_conns[tid] = std::move(c); } void tracker_manager::queue_request(