From: Tom de Vries Date: Tue, 17 Oct 2023 09:38:06 +0000 (+0200) Subject: [gdb/cli] Skip string copy in source_cache::ensure X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7e5649156720ec6c3aa5e2036b27811bc8195ab9;p=binutils-gdb.git [gdb/cli] Skip string copy in source_cache::ensure In function source_cache::ensure we have: ... std::ostringstream output; ... contents = output.str (); ... The last line causes an unnecessary string copy. C++20 allows us to skip it, like this: ... contents = std::move (output).str (); ... Use the more efficient solution. Tested on x86_64-linux. Reviewed-By: Lancelot Six --- diff --git a/gdb/source-cache.c b/gdb/source-cache.c index 77b357cb42b..ae02d2516d9 100644 --- a/gdb/source-cache.c +++ b/gdb/source-cache.c @@ -252,7 +252,7 @@ source_cache::ensure (struct symtab *s) std::istringstream input (contents); std::ostringstream output; highlighter->highlight (input, output, lang_name, fullname); - contents = output.str (); + contents = std::move (output).str (); already_styled = true; } catch (...)