From: Tom Tromey Date: Thu, 21 Sep 2023 19:31:14 +0000 (-0600) Subject: Use string_file::release in some places X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0128542673364609a0b2e1d8a3f1896fc89584d2;p=binutils-gdb.git Use string_file::release in some places I found a few spots like: string_file f; std::string x = f.string (); However, string_file::string returns a 'const std::string &'... so it seems to me that this must be copying the string (? I find it hard to reason about this in C++). This patch changes these spots to use release() instead, which moves the string. Reviewed-by: Keith Seitz Reviewed-by: Lancelot Six --- diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index d807ae3c9b5..f9b20a7d62d 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -7581,7 +7581,7 @@ bp_location::to_string () const string_file stb; ui_out_redirect_pop redir (current_uiout, &stb); print_breakpoint_location (this->owner, this); - return stb.string (); + return stb.release (); } /* Decrement reference count. If the reference count reaches 0, diff --git a/gdb/top.c b/gdb/top.c index 2322e55f1db..cbe14b01046 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -647,12 +647,12 @@ execute_fn_to_string (std::string &res, std::function fn, catch (...) { /* Finally. */ - res = std::move (str_file.string ()); + res = str_file.release (); throw; } /* And finally. */ - res = std::move (str_file.string ()); + res = str_file.release (); } /* See gdbcmd.h. */