From a024c515363ae6197ad1448e8b631540af36a148 Mon Sep 17 00:00:00 2001 From: wxf Date: Sun, 13 Sep 2020 11:07:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=AD=A6=E5=91=8A:=20moving?= =?UTF-8?q?=20a=20local=20object=20in=20a=20return=20statement=20prevents?= =?UTF-8?q?=20copy=20elision?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.viva64.com/en/w/v828/ 编译器会对返回本地变量优化([Named] Return Value Optimization (RVO/NRVO)), 无论是 C++11 之前还是之后, 添加 move 后反而会影响该优化. C++ Core Guidelines F.48: Do not return std::move(local) --- src/Record/HlsMakerImp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Record/HlsMakerImp.cpp b/src/Record/HlsMakerImp.cpp index 10521e36..4893687b 100644 --- a/src/Record/HlsMakerImp.cpp +++ b/src/Record/HlsMakerImp.cpp @@ -63,9 +63,9 @@ string HlsMakerImp::onOpenSegment(int index) { WarnL << "create file failed," << segment_path << " " << get_uv_errmsg(); } if (_params.empty()) { - return std::move(segment_name); + return segment_name; } - return std::move(segment_name + "?" + _params); + return segment_name + "?" + _params; } void HlsMakerImp::onDelSegment(int index) {