Skip to content

Commit

Permalink
rely on RVO in C++20
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Aug 24, 2023
1 parent b61ad8d commit a49bf1f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
6 changes: 6 additions & 0 deletions include/libtorrent/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,12 @@ POSSIBILITY OF SUCH DAMAGE.
#define __has_builtin(x) 0 // for non-clang compilers
#endif

#if __cplusplus >= 202002L
#define TORRENT_RVO(x) x
#else
#define TORRENT_RVO(x) std::move(x)
#endif

#if (TORRENT_HAS_SSE && defined __GNUC__)
# define TORRENT_HAS_BUILTIN_CLZ 1
#elif (TORRENT_HAS_ARM && defined __GNUC__ && !defined __clang__)
Expand Down
6 changes: 3 additions & 3 deletions src/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2579,7 +2579,7 @@ namespace {
for (int i = 0; i < m_v6_num_peers; i++)
peers.push_back(aux::read_v6_endpoint<tcp::endpoint>(v6_ptr));

return std::move(peers);
return TORRENT_RVO(peers);
}

dht_direct_response_alert::dht_direct_response_alert(
Expand Down Expand Up @@ -2819,7 +2819,7 @@ namespace {
nodes.emplace_back(ih, aux::read_v6_endpoint<udp::endpoint>(v6_ptr));
}

return std::move(nodes);
return TORRENT_RVO(nodes);
}
}

Expand Down Expand Up @@ -2931,7 +2931,7 @@ namespace {
char const* ptr = m_alloc.get().ptr(m_samples_idx);
std::memcpy(samples.data(), ptr, samples.size() * 20);

return std::move(samples);
return TORRENT_RVO(samples);
}

int dht_sample_infohashes_alert::num_nodes() const
Expand Down
2 changes: 1 addition & 1 deletion src/session_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ namespace {
stats[i].type = metrics[i].value_index >= counters::num_stats_counters
? metric_type_t::gauge : metric_type_t::counter;
}
return std::move(stats);
return TORRENT_RVO(stats);
}

int find_metric_idx(string_view name)
Expand Down
6 changes: 3 additions & 3 deletions src/torrent_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ namespace libtorrent {
{
aux::vector<std::int64_t, file_index_t> ret;
sync_call(&torrent::file_progress, std::ref(ret), flags);
return std::move(ret);
return TORRENT_RVO(ret);
}

void torrent_handle::post_file_progress(file_progress_flags_t const flags) const
Expand Down Expand Up @@ -542,7 +542,7 @@ namespace libtorrent {
aux::vector<download_priority_t, piece_index_t> ret;
auto retp = &ret;
sync_call(&torrent::piece_priorities, retp);
return std::move(ret);
return TORRENT_RVO(ret);
}

#if TORRENT_ABI_VERSION == 1
Expand Down Expand Up @@ -598,7 +598,7 @@ namespace libtorrent {
aux::vector<download_priority_t, file_index_t> ret;
auto retp = &ret;
sync_call(&torrent::file_priorities, retp);
return std::move(ret);
return TORRENT_RVO(ret);
}

#if TORRENT_ABI_VERSION == 1
Expand Down

0 comments on commit a49bf1f

Please sign in to comment.