public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: remove unnecessary call to std::string constructor
@ 2023-05-11 17:33 Simon Marchi
  2023-05-12 18:44 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2023-05-11 17:33 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

I spotted this explicit call to std::string, which creates an
unnecessary temporary extra std::string, while calling emplace_back.
I'm not sure if it has any impact in an optimized build, maybe the
compiler elides it.  But still, it's unnecessary.

Change-Id: I873337ea91db29ac06267aff8fc12dcf52824cac
---
 gdb/cli/cli-decode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 948592a6f621..b84ce8375fb7 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -155,7 +155,7 @@ cmd_list_element::command_components () const
   if (this->prefix != nullptr)
     result = this->prefix->command_components ();
 
-  result.emplace_back (std::string (this->name));
+  result.emplace_back (this->name);
   return result;
 }
 

base-commit: b7ea736a38013510cd0496b42a8eb2dd2d2f6830
-- 
2.40.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: remove unnecessary call to std::string constructor
  2023-05-11 17:33 [PATCH] gdb: remove unnecessary call to std::string constructor Simon Marchi
@ 2023-05-12 18:44 ` Tom Tromey
  2023-05-12 18:50   ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2023-05-12 18:44 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> I spotted this explicit call to std::string, which creates an
Simon> unnecessary temporary extra std::string, while calling emplace_back.
Simon> I'm not sure if it has any impact in an optimized build, maybe the
Simon> compiler elides it.  But still, it's unnecessary.

It probably just moves the new string, but I agree it's better with your patch.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: remove unnecessary call to std::string constructor
  2023-05-12 18:44 ` Tom Tromey
@ 2023-05-12 18:50   ` Simon Marchi
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2023-05-12 18:50 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches

On 5/12/23 14:44, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> I spotted this explicit call to std::string, which creates an
> Simon> unnecessary temporary extra std::string, while calling emplace_back.
> Simon> I'm not sure if it has any impact in an optimized build, maybe the
> Simon> compiler elides it.  But still, it's unnecessary.
> 
> It probably just moves the new string, but I agree it's better with your patch.

Thanks, pushed.

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-12 18:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-11 17:33 [PATCH] gdb: remove unnecessary call to std::string constructor Simon Marchi
2023-05-12 18:44 ` Tom Tromey
2023-05-12 18:50   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).