Avoid needless container and scoped_refptr copies Several call sites deep-copy Codec, Candidate and logged RTP stream objects, or whole vectors of them, that they only read. A few constructors also copy by-value scoped_refptr parameters instead of moving them. - Bind getter results and loop elements by const reference: the codec lists in the SDP munging detector and in CodecList's AbslStringify, the port candidates in GetCandidateStatsFromReadyPorts, and the logged RTP streams in the NetEq event log input. - Move by-value scoped_refptr parameters into their members in the PeerConnection, BroadcastResourceListener and ResourceVideoSendStreamForwarder constructors. Bug: webrtc:374845009 Change-Id: I7f213313c894252896ccd3f39c03f455d5e84566 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/498621 Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org> Cr-Commit-Position: refs/heads/main@{#48805}
diff --git a/call/adaptation/broadcast_resource_listener.cc b/call/adaptation/broadcast_resource_listener.cc index 5305964..2a9c447 100644 --- a/call/adaptation/broadcast_resource_listener.cc +++ b/call/adaptation/broadcast_resource_listener.cc
@@ -57,7 +57,7 @@ BroadcastResourceListener::BroadcastResourceListener( scoped_refptr<Resource> source_resource) - : source_resource_(source_resource), is_listening_(false) { + : source_resource_(std::move(source_resource)), is_listening_(false) { RTC_DCHECK(source_resource_); }
diff --git a/call/call.cc b/call/call.cc index 6ce9c7f..a848c64 100644 --- a/call/call.cc +++ b/call/call.cc
@@ -167,7 +167,7 @@ public: explicit ResourceVideoSendStreamForwarder( scoped_refptr<webrtc::Resource> resource) - : broadcast_resource_listener_(resource) { + : broadcast_resource_listener_(std::move(resource)) { broadcast_resource_listener_.StartListening(); } ~ResourceVideoSendStreamForwarder() {
diff --git a/media/base/codec_list.h b/media/base/codec_list.h index 6f87f90..021fde2 100644 --- a/media/base/codec_list.h +++ b/media/base/codec_list.h
@@ -100,7 +100,7 @@ template <typename Sink> friend void AbslStringify(Sink& sink, const CodecList& list) { absl::Format(&sink, "\n--- Codec list of size %d\n", list.size()); - for (Codec codec : list) { + for (const Codec& codec : list) { absl::Format(&sink, "%v\n", codec); } sink.Append("--- End\n");
diff --git a/modules/audio_coding/neteq/tools/neteq_event_log_input.cc b/modules/audio_coding/neteq/tools/neteq_event_log_input.cc index f7834c6..27a617a 100644 --- a/modules/audio_coding/neteq/tools/neteq_event_log_input.cc +++ b/modules/audio_coding/neteq/tools/neteq_event_log_input.cc
@@ -163,10 +163,10 @@ } // Pick the first SSRC if none was provided. ssrc = ssrc.value_or(*parsed_log.incoming_audio_ssrcs().begin()); - auto streams = parsed_log.incoming_rtp_packets_by_ssrc(); + const auto& streams = parsed_log.incoming_rtp_packets_by_ssrc(); auto stream = std::find_if(streams.begin(), streams.end(), - [ssrc](auto stream) { return stream.ssrc == ssrc; }); + [ssrc](const auto& stream) { return stream.ssrc == ssrc; }); if (stream == streams.end()) { return nullptr; }
diff --git a/p2p/client/basic_port_allocator.cc b/p2p/client/basic_port_allocator.cc index 1950d73..15cca3b 100644 --- a/p2p/client/basic_port_allocator.cc +++ b/p2p/client/basic_port_allocator.cc
@@ -477,7 +477,7 @@ CandidateStatsList* candidate_stats_list) const { auto ports = ReadyPorts(); for (auto* port : ports) { - auto candidates = port->Candidates(); + const auto& candidates = port->Candidates(); for (const auto& candidate : candidates) { std::optional<StunStats> stun_stats; port->GetStunStats(&stun_stats);
diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 15a0e4e..10e6ff9 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc
@@ -471,7 +471,7 @@ const std::vector<RelayServerConfig>& turn_servers, bool dtls_enabled) : env_(env), - context_(context), + context_(std::move(context)), options_(options), observer_(dependencies.observer), is_unified_plan_(is_unified_plan),
diff --git a/pc/sdp_munging_detector.cc b/pc/sdp_munging_detector.cc index bed58ed..31129d2 100644 --- a/pc/sdp_munging_detector.cc +++ b/pc/sdp_munging_detector.cc
@@ -310,8 +310,8 @@ MediaType media_type = last_created_media_description->type(); // Validate codecs. We should have bailed out earlier if codecs were added // or removed. - auto last_created_codecs = last_created_media_description->codecs(); - auto codecs_to_set = media_description_to_set->codecs(); + const auto& last_created_codecs = last_created_media_description->codecs(); + const auto& codecs_to_set = media_description_to_set->codecs(); if (last_created_codecs.size() == codecs_to_set.size()) { for (size_t i = 0; i < last_created_codecs.size(); i++) { if (last_created_codecs[i] == codecs_to_set[i]) {