From c759f832e9bb4fc679ec7a88263bc8af4abdf908 Mon Sep 17 00:00:00 2001 From: Minyue Li Date: Fri, 9 Aug 2019 13:20:03 +0200 Subject: [PATCH] Avoid copying of vectors in RtpPacketInfos. Bug: chromium:982260 Change-Id: Ia4dab497b662e825f80c16530cdf615b62f0a5c9 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/148523 Commit-Queue: Minyue Li Reviewed-by: Per Kjellander Reviewed-by: Chen Xing Cr-Commit-Position: refs/heads/master@{#28859} --- api/rtp_packet_infos.h | 21 ++++++++++++++++++--- modules/audio_coding/neteq/neteq_impl.cc | 3 +-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/api/rtp_packet_infos.h b/api/rtp_packet_infos.h index c2b595a898..08da1aee61 100644 --- a/api/rtp_packet_infos.h +++ b/api/rtp_packet_infos.h @@ -12,6 +12,7 @@ #define API_RTP_PACKET_INFOS_H_ #include +#include #include #include "api/ref_counted_base.h" @@ -46,7 +47,11 @@ class RtpPacketInfos { using reverse_iterator = const_reverse_iterator; RtpPacketInfos() {} - explicit RtpPacketInfos(vector_type entries) : data_(Data::Create(entries)) {} + explicit RtpPacketInfos(const vector_type& entries) + : data_(Data::Create(entries)) {} + + explicit RtpPacketInfos(vector_type&& entries) + : data_(Data::Create(std::move(entries))) {} RtpPacketInfos(const RtpPacketInfos& other) = default; RtpPacketInfos(RtpPacketInfos&& other) = default; @@ -75,7 +80,7 @@ class RtpPacketInfos { private: class Data : public rtc::RefCountedBase { public: - static rtc::scoped_refptr Create(vector_type entries) { + static rtc::scoped_refptr Create(const vector_type& entries) { // Performance optimization for the empty case. if (entries.empty()) { return nullptr; @@ -84,10 +89,20 @@ class RtpPacketInfos { return new Data(entries); } + static rtc::scoped_refptr Create(vector_type&& entries) { + // Performance optimization for the empty case. + if (entries.empty()) { + return nullptr; + } + + return new Data(std::move(entries)); + } + const vector_type& entries() const { return entries_; } private: - explicit Data(vector_type entries) : entries_(entries) {} + explicit Data(const vector_type& entries) : entries_(entries) {} + explicit Data(vector_type&& entries) : entries_(std::move(entries)) {} ~Data() override {} const vector_type entries_; diff --git a/modules/audio_coding/neteq/neteq_impl.cc b/modules/audio_coding/neteq/neteq_impl.cc index 5466409395..f17884224d 100644 --- a/modules/audio_coding/neteq/neteq_impl.cc +++ b/modules/audio_coding/neteq/neteq_impl.cc @@ -898,8 +898,7 @@ int NetEqImpl::GetAudioInternal(AudioFrame* audio_frame, // We treat it as if all packets referenced to by |last_decoded_packet_infos_| // were mashed together when creating the samples in |algorithm_buffer_|. - RtpPacketInfos packet_infos(std::move(last_decoded_packet_infos_)); - last_decoded_packet_infos_.clear(); + RtpPacketInfos packet_infos(last_decoded_packet_infos_); // Copy samples from |algorithm_buffer_| to |sync_buffer_|. //