gdb: add string_file::release method

A common pattern for string_file is to want to move out the internal
string buffer, because it is the result of the computation that we want
to return.  It is the reason why string_file::string returns a non-const
reference, as explained in the comment.  I think it would make sense to
have a dedicated method for that instead and make string_file::string
return a const reference.

This allows removing the explicit std::move in the typical case.  Note
that compile_program::compute was missing a move, meaning that the
resulting string was copied.  With the new version, it's not possible to
forget to move.

Change-Id: Ieaefa35b73daa7930b2f3a26988b6e3b4121bb79
This commit is contained in:
Simon Marchi
2022-01-24 20:00:46 -05:00
parent b583c328e7
commit 5d10a2041e
17 changed files with 37 additions and 36 deletions

View File

@@ -82,7 +82,7 @@ ada_varobj_scalar_image (struct type *type, LONGEST val)
string_file buf;
ada_print_scalar (type, val, &buf);
return std::move (buf.string ());
return buf.release ();
}
/* Assuming that the (PARENT_VALUE, PARENT_TYPE) pair designates
@@ -817,7 +817,7 @@ ada_varobj_get_value_image (struct value *value,
string_file buffer;
common_val_print (value, &buffer, 0, opts, current_language);
return std::move (buffer.string ());
return buffer.release ();
}
/* Assuming that the (VALUE, TYPE) pair designates an array varobj,