forked from Imagelibrary/binutils-gdb
Use std::string in do_set_command
do_set_command manually updates a string, only to copy it to a std::string and free the working copy. This patch changes this code to use std::string for everything, simplifying the code and removing a copy. Reviewed-by: John Baldwin <jhb@FreeBSD.org>
This commit is contained in:
@@ -340,14 +340,12 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
|
|||||||
{
|
{
|
||||||
case var_string:
|
case var_string:
|
||||||
{
|
{
|
||||||
char *newobj;
|
std::string newobj;
|
||||||
const char *p;
|
const char *p;
|
||||||
char *q;
|
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
newobj = (char *) xmalloc (strlen (arg) + 2);
|
newobj.reserve (strlen (arg));
|
||||||
p = arg;
|
p = arg;
|
||||||
q = newobj;
|
|
||||||
while ((ch = *p++) != '\000')
|
while ((ch = *p++) != '\000')
|
||||||
{
|
{
|
||||||
if (ch == '\\')
|
if (ch == '\\')
|
||||||
@@ -365,20 +363,14 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
|
|||||||
if (ch == 0)
|
if (ch == 0)
|
||||||
break; /* C loses */
|
break; /* C loses */
|
||||||
else if (ch > 0)
|
else if (ch > 0)
|
||||||
*q++ = ch;
|
newobj.push_back (ch);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*q++ = ch;
|
newobj.push_back (ch);
|
||||||
}
|
}
|
||||||
#if 0
|
newobj.shrink_to_fit ();
|
||||||
if (*(p - 1) != '\\')
|
|
||||||
*q++ = ' ';
|
|
||||||
#endif
|
|
||||||
*q++ = '\0';
|
|
||||||
newobj = (char *) xrealloc (newobj, q - newobj);
|
|
||||||
|
|
||||||
option_changed = c->var->set<std::string> (std::string (newobj));
|
option_changed = c->var->set<std::string> (std::move (newobj));
|
||||||
xfree (newobj);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case var_string_noescape:
|
case var_string_noescape:
|
||||||
|
|||||||
Reference in New Issue
Block a user