gdb: remove unnecessary call to std::string constructor

Message ID 20230511173351.41358-1-simon.marchi@efficios.com
State New
Headers
Series gdb: remove unnecessary call to std::string constructor |

Commit Message

Simon Marchi May 11, 2023, 5:33 p.m. UTC
  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(-)


base-commit: b7ea736a38013510cd0496b42a8eb2dd2d2f6830
  

Comments

Tom Tromey May 12, 2023, 6:44 p.m. UTC | #1
>>>>> "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
  
Simon Marchi May 12, 2023, 6:50 p.m. UTC | #2
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
  

Patch

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;
 }