Skip to content

Commit

Permalink
Move construct std::shared_ptr objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobo1 authored and arvidn committed Oct 26, 2024
1 parent 569f738 commit 1b8dc12
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/alert_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace aux {
#ifndef TORRENT_DISABLE_EXTENSIONS
void alert_manager::add_extension(std::shared_ptr<plugin> ext)
{
m_ses_extensions.push_back(ext);
m_ses_extensions.push_back(std::move(ext));
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/disk_buffer_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/file_view_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
4 changes: 2 additions & 2 deletions src/mmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::size_t>(m_size), advise);
::madvise(m_mapping, static_cast<std::size_t>(m_size), advise);
}
#endif
}
Expand All @@ -227,7 +227,7 @@ file_mapping::file_mapping(file_handle file, open_mode_t const mode
, std::shared_ptr<std::mutex> 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<std::size_t>(m_size)))
{
Expand Down
2 changes: 1 addition & 1 deletion src/peer_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ namespace libtorrent {
void peer_connection::add_extension(std::shared_ptr<peer_plugin> 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)
Expand Down
9 changes: 5 additions & 4 deletions src/torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1480,19 +1480,20 @@ bool is_downloading_state(int const st)

void torrent::add_extension(std::shared_ptr<torrent_plugin> 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<peer_plugin> pp(ext->new_connection(peer_connection_handle(p->self())));
std::shared_ptr<peer_plugin> 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<torrent_plugin> ext)
Expand All @@ -1508,7 +1509,7 @@ bool is_downloading_state(int const st)
std::shared_ptr<torrent_plugin> tp(ext(get_handle(), userdata));
if (!tp) return;

add_extension(tp);
add_extension(std::move(tp));
}

#endif
Expand Down
2 changes: 1 addition & 1 deletion src/tracker_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1b8dc12

Please sign in to comment.