From d28ee4eee8b777b75eb103b95bf0ed18ef26a124 Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 24 Aug 2023 16:34:21 +0200 Subject: [PATCH] rely on RVO in C++20 --- bindings/python/src/entry.cpp | 4 ++-- include/libtorrent/config.hpp | 6 ++++++ src/alert.cpp | 6 +++--- src/session_stats.cpp | 2 +- src/torrent_handle.cpp | 4 ++-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/bindings/python/src/entry.cpp b/bindings/python/src/entry.cpp index 6e0ee74aadb..e4c55aa14a3 100644 --- a/bindings/python/src/entry.cpp +++ b/bindings/python/src/entry.cpp @@ -20,7 +20,7 @@ struct entry_to_python result.append(*i); } - return std::move(result); + return TORRENT_RVO(result); } static object convert(entry::dictionary_type const& d) @@ -30,7 +30,7 @@ struct entry_to_python for (entry::dictionary_type::const_iterator i(d.begin()), e(d.end()); i != e; ++i) result[bytes(i->first)] = i->second; - return std::move(result); + return TORRENT_RVO(result); } static object convert0(entry const& e) diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 84e2b845575..76091984dcf 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -579,6 +579,12 @@ constexpr std::size_t TORRENT_WRITE_HANDLER_MAX_SIZE = 400; #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__) diff --git a/src/alert.cpp b/src/alert.cpp index 0ac87588906..1e24a4d9e22 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -2531,7 +2531,7 @@ namespace { for (int i = 0; i < m_v6_num_peers; i++) peers.push_back(detail::read_v6_endpoint(v6_ptr)); - return std::move(peers); + return TORRENT_RVO(peers); } dht_direct_response_alert::dht_direct_response_alert( @@ -2771,7 +2771,7 @@ namespace { nodes.emplace_back(ih, detail::read_v6_endpoint(v6_ptr)); } - return std::move(nodes); + return TORRENT_RVO(nodes); } } @@ -2881,7 +2881,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 diff --git a/src/session_stats.cpp b/src/session_stats.cpp index 7a96fa9b1d2..147cd7e29b8 100644 --- a/src/session_stats.cpp +++ b/src/session_stats.cpp @@ -585,7 +585,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) diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 0b856439d11..82e26f70206 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -487,7 +487,7 @@ namespace libtorrent { aux::vector ret; auto retp = &ret; sync_call(&torrent::piece_priorities, retp); - return std::move(ret); + return TORRENT_RVO(ret); } #if TORRENT_ABI_VERSION == 1 @@ -543,7 +543,7 @@ namespace libtorrent { aux::vector ret; auto retp = &ret; sync_call(&torrent::file_priorities, retp); - return std::move(ret); + return TORRENT_RVO(ret); } #if TORRENT_ABI_VERSION == 1