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 26, 2023
1 parent fb6a455 commit d28ee4e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions bindings/python/src/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions include/libtorrent/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
6 changes: 3 additions & 3 deletions src/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2531,7 +2531,7 @@ namespace {
for (int i = 0; i < m_v6_num_peers; i++)
peers.push_back(detail::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 @@ -2771,7 +2771,7 @@ namespace {
nodes.emplace_back(ih, detail::read_v6_endpoint<udp::endpoint>(v6_ptr));
}

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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/session_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/torrent_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,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 @@ -543,7 +543,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 d28ee4e

Please sign in to comment.