From 1c54605e77e07fa9b69b763e63e2af6c4c0d0d8e Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Mon, 4 Feb 2019 14:50:38 +0100 Subject: [PATCH] [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 Commit-Queue: Mirko Bonadei Cr-Commit-Position: refs/heads/master@{#26553} --- api/audio_codecs/audio_format.cc | 11 +++++++++++ api/audio_codecs/audio_format.h | 4 ++++ audio/channel_send.cc | 2 +- logging/rtc_event_log/rtc_event_log_parser.cc | 4 ++-- modules/audio_device/audio_device_name.cc | 3 +-- modules/audio_device/audio_device_name.h | 2 +- pc/peer_connection_ice_unittest.cc | 2 +- pc/transport_stats.cc | 4 ---- pc/transport_stats.h | 3 --- rtc_base/function_view_unittest.cc | 3 ++- 10 files changed, 23 insertions(+), 15 deletions(-) diff --git a/api/audio_codecs/audio_format.cc b/api/audio_codecs/audio_format.cc index 11788b91e8..2a529a49ee 100644 --- a/api/audio_codecs/audio_format.cc +++ b/api/audio_codecs/audio_format.cc @@ -10,6 +10,8 @@ #include "api/audio_codecs/audio_format.h" +#include + #include "absl/strings/match.h" namespace webrtc { @@ -31,6 +33,15 @@ SdpAudioFormat::SdpAudioFormat(absl::string_view name, num_channels(num_channels), 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 { return absl::EqualsIgnoreCase(name, o.name) && clockrate_hz == o.clockrate_hz && num_channels == o.num_channels; diff --git a/api/audio_codecs/audio_format.h b/api/audio_codecs/audio_format.h index b8b042178b..053c067302 100644 --- a/api/audio_codecs/audio_format.h +++ b/api/audio_codecs/audio_format.h @@ -32,6 +32,10 @@ struct RTC_EXPORT SdpAudioFormat { int clockrate_hz, size_t num_channels, const Parameters& param); + SdpAudioFormat(absl::string_view name, + int clockrate_hz, + size_t num_channels, + Parameters&& param); ~SdpAudioFormat(); // Returns true if this format is compatible with |o|. In SDP terminology: diff --git a/audio/channel_send.cc b/audio/channel_send.cc index dfbbb5799f..e7408f0a85 100644 --- a/audio/channel_send.cc +++ b/audio/channel_send.cc @@ -587,7 +587,7 @@ int32_t ChannelSend::SendMediaTransportAudio( sampling_rate_hz = media_transport_sampling_frequency_; channel_id = media_transport_channel_id_; } - const MediaTransportEncodedAudioFrame frame( + MediaTransportEncodedAudioFrame frame( /*sampling_rate_hz=*/sampling_rate_hz, // TODO(nisse): Timestamp and sample index are the same for all supported diff --git a/logging/rtc_event_log/rtc_event_log_parser.cc b/logging/rtc_event_log/rtc_event_log_parser.cc index 30e8a51a2b..1a0c8eb014 100644 --- a/logging/rtc_event_log/rtc_event_log_parser.cc +++ b/logging/rtc_event_log/rtc_event_log_parser.cc @@ -1051,7 +1051,7 @@ bool ParsedRtcEventLog::ParseStream( // Since we dont need rapid lookup based on SSRC after parsing, we move the // packets_streams from map to vector. 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_.back().ssrc = kv.first; incoming_rtp_packets_by_ssrc_.back().incoming_packets = @@ -1059,7 +1059,7 @@ bool ParsedRtcEventLog::ParseStream( } incoming_rtp_packets_map_.clear(); 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_.back().ssrc = kv.first; outgoing_rtp_packets_by_ssrc_.back().outgoing_packets = diff --git a/modules/audio_device/audio_device_name.cc b/modules/audio_device/audio_device_name.cc index 0a1ed0c968..92d8ba1bcd 100644 --- a/modules/audio_device/audio_device_name.cc +++ b/modules/audio_device/audio_device_name.cc @@ -17,8 +17,7 @@ namespace webrtc { const char AudioDeviceName::kDefaultDeviceId[] = "default"; const char AudioDeviceName::kDefaultCommunicationsDeviceId[] = "communications"; -AudioDeviceName::AudioDeviceName(const std::string device_name, - const std::string unique_id) +AudioDeviceName::AudioDeviceName(std::string device_name, std::string unique_id) : device_name(std::move(device_name)), unique_id(std::move(unique_id)) {} bool AudioDeviceName::IsValid() { diff --git a/modules/audio_device/audio_device_name.h b/modules/audio_device/audio_device_name.h index c03384e409..267366344a 100644 --- a/modules/audio_device/audio_device_name.h +++ b/modules/audio_device/audio_device_name.h @@ -24,7 +24,7 @@ struct AudioDeviceName { static const char kDefaultCommunicationsDeviceId[]; AudioDeviceName() = default; - AudioDeviceName(const std::string device_name, const std::string unique_id); + AudioDeviceName(std::string device_name, std::string unique_id); ~AudioDeviceName() = default; diff --git a/pc/peer_connection_ice_unittest.cc b/pc/peer_connection_ice_unittest.cc index 1d525e3642..5499c830d9 100644 --- a/pc/peer_connection_ice_unittest.cc +++ b/pc/peer_connection_ice_unittest.cc @@ -994,7 +994,7 @@ class PeerConnectionIceConfigTest : public testing::Test { nullptr /* cert_generator */, &observer_)); EXPECT_TRUE(pc.get()); - pc_ = std::move(pc.get()); + pc_ = std::move(pc); } rtc::scoped_refptr pc_factory_ = nullptr; diff --git a/pc/transport_stats.cc b/pc/transport_stats.cc index f6dd7d6fdf..8049c07a77 100644 --- a/pc/transport_stats.cc +++ b/pc/transport_stats.cc @@ -18,8 +18,4 @@ TransportChannelStats::TransportChannelStats(const TransportChannelStats&) = TransportChannelStats::~TransportChannelStats() = default; -TransportStats::TransportStats() = default; - -TransportStats::~TransportStats() = default; - } // namespace cricket diff --git a/pc/transport_stats.h b/pc/transport_stats.h index 8813dbec5f..bec1c2b065 100644 --- a/pc/transport_stats.h +++ b/pc/transport_stats.h @@ -39,9 +39,6 @@ typedef std::vector TransportChannelStatsList; // Information about the stats of a transport. struct TransportStats { - TransportStats(); - ~TransportStats(); - std::string transport_name; TransportChannelStatsList channel_stats; }; diff --git a/rtc_base/function_view_unittest.cc b/rtc_base/function_view_unittest.cc index 535fae83c9..d91bac02e2 100644 --- a/rtc_base/function_view_unittest.cc +++ b/rtc_base/function_view_unittest.cc @@ -97,6 +97,7 @@ TEST(FunctionViewTest, CopyConstructor) { TEST(FunctionViewTest, MoveConstructorIsCopy) { auto f17 = [] { return 17; }; rtc::FunctionView fv1(f17); + // NOLINTNEXTLINE(performance-move-const-arg) rtc::FunctionView fv2(std::move(fv1)); EXPECT_EQ(17, fv1()); EXPECT_EQ(17, fv2()); @@ -121,7 +122,7 @@ TEST(FunctionViewTest, MoveAssignmentIsCopy) { rtc::FunctionView fv2(f23); EXPECT_EQ(17, fv1()); EXPECT_EQ(23, fv2()); - fv2 = std::move(fv1); + fv2 = std::move(fv1); // NOLINT(performance-move-const-arg) EXPECT_EQ(17, fv1()); EXPECT_EQ(17, fv2()); }