[clang-tidy] Apply performance-move-const-arg fixes (misc).

This CL is a manual spin-off of [1], which tried to apply clang-tidy's
performance-move-const-arg [1] to the WebRTC codebase.

Since there were some wrong fixes to correct, this CL lands a few
different fixes, like adding a constructor overload to take an rvalue
reference or remove 'const' to make std::move effective.

[1] - https://webrtc-review.googlesource.com/c/src/+/120350
[2] - https://clang.llvm.org/extra/clang-tidy/checks/performance-move-const-arg.html

Bug: webrtc:10252
Change-Id: I42a777247fee2cb788efcd7c2035148330056b7a
Reviewed-on: https://webrtc-review.googlesource.com/c/120928
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26553}
This commit is contained in:
Mirko Bonadei
2019-02-04 14:50:38 +01:00
committed by Commit Bot
parent 87ce874f99
commit 1c54605e77
10 changed files with 23 additions and 15 deletions

View File

@ -10,6 +10,8 @@
#include "api/audio_codecs/audio_format.h" #include "api/audio_codecs/audio_format.h"
#include <utility>
#include "absl/strings/match.h" #include "absl/strings/match.h"
namespace webrtc { namespace webrtc {
@ -31,6 +33,15 @@ SdpAudioFormat::SdpAudioFormat(absl::string_view name,
num_channels(num_channels), num_channels(num_channels),
parameters(param) {} parameters(param) {}
SdpAudioFormat::SdpAudioFormat(absl::string_view name,
int clockrate_hz,
size_t num_channels,
Parameters&& param)
: name(name),
clockrate_hz(clockrate_hz),
num_channels(num_channels),
parameters(std::move(param)) {}
bool SdpAudioFormat::Matches(const SdpAudioFormat& o) const { bool SdpAudioFormat::Matches(const SdpAudioFormat& o) const {
return absl::EqualsIgnoreCase(name, o.name) && return absl::EqualsIgnoreCase(name, o.name) &&
clockrate_hz == o.clockrate_hz && num_channels == o.num_channels; clockrate_hz == o.clockrate_hz && num_channels == o.num_channels;

View File

@ -32,6 +32,10 @@ struct RTC_EXPORT SdpAudioFormat {
int clockrate_hz, int clockrate_hz,
size_t num_channels, size_t num_channels,
const Parameters& param); const Parameters& param);
SdpAudioFormat(absl::string_view name,
int clockrate_hz,
size_t num_channels,
Parameters&& param);
~SdpAudioFormat(); ~SdpAudioFormat();
// Returns true if this format is compatible with |o|. In SDP terminology: // Returns true if this format is compatible with |o|. In SDP terminology:

View File

@ -587,7 +587,7 @@ int32_t ChannelSend::SendMediaTransportAudio(
sampling_rate_hz = media_transport_sampling_frequency_; sampling_rate_hz = media_transport_sampling_frequency_;
channel_id = media_transport_channel_id_; channel_id = media_transport_channel_id_;
} }
const MediaTransportEncodedAudioFrame frame( MediaTransportEncodedAudioFrame frame(
/*sampling_rate_hz=*/sampling_rate_hz, /*sampling_rate_hz=*/sampling_rate_hz,
// TODO(nisse): Timestamp and sample index are the same for all supported // TODO(nisse): Timestamp and sample index are the same for all supported

View File

@ -1051,7 +1051,7 @@ bool ParsedRtcEventLog::ParseStream(
// Since we dont need rapid lookup based on SSRC after parsing, we move the // Since we dont need rapid lookup based on SSRC after parsing, we move the
// packets_streams from map to vector. // packets_streams from map to vector.
incoming_rtp_packets_by_ssrc_.reserve(incoming_rtp_packets_map_.size()); incoming_rtp_packets_by_ssrc_.reserve(incoming_rtp_packets_map_.size());
for (const auto& kv : incoming_rtp_packets_map_) { for (auto& kv : incoming_rtp_packets_map_) {
incoming_rtp_packets_by_ssrc_.emplace_back(LoggedRtpStreamIncoming()); incoming_rtp_packets_by_ssrc_.emplace_back(LoggedRtpStreamIncoming());
incoming_rtp_packets_by_ssrc_.back().ssrc = kv.first; incoming_rtp_packets_by_ssrc_.back().ssrc = kv.first;
incoming_rtp_packets_by_ssrc_.back().incoming_packets = incoming_rtp_packets_by_ssrc_.back().incoming_packets =
@ -1059,7 +1059,7 @@ bool ParsedRtcEventLog::ParseStream(
} }
incoming_rtp_packets_map_.clear(); incoming_rtp_packets_map_.clear();
outgoing_rtp_packets_by_ssrc_.reserve(outgoing_rtp_packets_map_.size()); outgoing_rtp_packets_by_ssrc_.reserve(outgoing_rtp_packets_map_.size());
for (const auto& kv : outgoing_rtp_packets_map_) { for (auto& kv : outgoing_rtp_packets_map_) {
outgoing_rtp_packets_by_ssrc_.emplace_back(LoggedRtpStreamOutgoing()); outgoing_rtp_packets_by_ssrc_.emplace_back(LoggedRtpStreamOutgoing());
outgoing_rtp_packets_by_ssrc_.back().ssrc = kv.first; outgoing_rtp_packets_by_ssrc_.back().ssrc = kv.first;
outgoing_rtp_packets_by_ssrc_.back().outgoing_packets = outgoing_rtp_packets_by_ssrc_.back().outgoing_packets =

View File

@ -17,8 +17,7 @@ namespace webrtc {
const char AudioDeviceName::kDefaultDeviceId[] = "default"; const char AudioDeviceName::kDefaultDeviceId[] = "default";
const char AudioDeviceName::kDefaultCommunicationsDeviceId[] = "communications"; const char AudioDeviceName::kDefaultCommunicationsDeviceId[] = "communications";
AudioDeviceName::AudioDeviceName(const std::string device_name, AudioDeviceName::AudioDeviceName(std::string device_name, std::string unique_id)
const std::string unique_id)
: device_name(std::move(device_name)), unique_id(std::move(unique_id)) {} : device_name(std::move(device_name)), unique_id(std::move(unique_id)) {}
bool AudioDeviceName::IsValid() { bool AudioDeviceName::IsValid() {

View File

@ -24,7 +24,7 @@ struct AudioDeviceName {
static const char kDefaultCommunicationsDeviceId[]; static const char kDefaultCommunicationsDeviceId[];
AudioDeviceName() = default; AudioDeviceName() = default;
AudioDeviceName(const std::string device_name, const std::string unique_id); AudioDeviceName(std::string device_name, std::string unique_id);
~AudioDeviceName() = default; ~AudioDeviceName() = default;

View File

@ -994,7 +994,7 @@ class PeerConnectionIceConfigTest : public testing::Test {
nullptr /* cert_generator */, nullptr /* cert_generator */,
&observer_)); &observer_));
EXPECT_TRUE(pc.get()); EXPECT_TRUE(pc.get());
pc_ = std::move(pc.get()); pc_ = std::move(pc);
} }
rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory_ = nullptr; rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory_ = nullptr;

View File

@ -18,8 +18,4 @@ TransportChannelStats::TransportChannelStats(const TransportChannelStats&) =
TransportChannelStats::~TransportChannelStats() = default; TransportChannelStats::~TransportChannelStats() = default;
TransportStats::TransportStats() = default;
TransportStats::~TransportStats() = default;
} // namespace cricket } // namespace cricket

View File

@ -39,9 +39,6 @@ typedef std::vector<TransportChannelStats> TransportChannelStatsList;
// Information about the stats of a transport. // Information about the stats of a transport.
struct TransportStats { struct TransportStats {
TransportStats();
~TransportStats();
std::string transport_name; std::string transport_name;
TransportChannelStatsList channel_stats; TransportChannelStatsList channel_stats;
}; };

View File

@ -97,6 +97,7 @@ TEST(FunctionViewTest, CopyConstructor) {
TEST(FunctionViewTest, MoveConstructorIsCopy) { TEST(FunctionViewTest, MoveConstructorIsCopy) {
auto f17 = [] { return 17; }; auto f17 = [] { return 17; };
rtc::FunctionView<int()> fv1(f17); rtc::FunctionView<int()> fv1(f17);
// NOLINTNEXTLINE(performance-move-const-arg)
rtc::FunctionView<int()> fv2(std::move(fv1)); rtc::FunctionView<int()> fv2(std::move(fv1));
EXPECT_EQ(17, fv1()); EXPECT_EQ(17, fv1());
EXPECT_EQ(17, fv2()); EXPECT_EQ(17, fv2());
@ -121,7 +122,7 @@ TEST(FunctionViewTest, MoveAssignmentIsCopy) {
rtc::FunctionView<int()> fv2(f23); rtc::FunctionView<int()> fv2(f23);
EXPECT_EQ(17, fv1()); EXPECT_EQ(17, fv1());
EXPECT_EQ(23, fv2()); EXPECT_EQ(23, fv2());
fv2 = std::move(fv1); fv2 = std::move(fv1); // NOLINT(performance-move-const-arg)
EXPECT_EQ(17, fv1()); EXPECT_EQ(17, fv1());
EXPECT_EQ(17, fv2()); EXPECT_EQ(17, fv2());
} }