Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb: Use vector::emplace_back
@ 2016-11-09  0:39 Pedro Alves
  2016-11-09 11:12 ` Yao Qi
  0 siblings, 1 reply; 9+ messages in thread
From: Pedro Alves @ 2016-11-09  0:39 UTC (permalink / raw)
  To: gdb-patches

Now that we require C++11, we can use vector::emplace_back to
construct elements in place instead of constructing and then copying.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* main.c (struct cmdarg): Add constructor.
	(captured_main_1): Use vector::emplace_back.
	* tracepoint.c (collection_list::add_memrange): Likewise.
---
 gdb/main.c       | 31 ++++++++++---------------------
 gdb/tracepoint.c |  2 +-
 2 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/gdb/main.c b/gdb/main.c
index ca6a81e..fe57bf8 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -444,7 +444,12 @@ enum cmdarg_kind
 };
 
 /* Arguments of --command option and its counterpart.  */
-struct cmdarg {
+struct cmdarg
+{
+  cmdarg (cmdarg_kind type_, char *string_)
+    : type (type_), string (string_)
+  {}
+
   /* Type of this option.  */
   enum cmdarg_kind type;
 
@@ -745,32 +750,16 @@ captured_main_1 (struct captured_main_args *context)
 	    pidarg = optarg;
 	    break;
 	  case 'x':
-	    {
-	      struct cmdarg cmdarg = { CMDARG_FILE, optarg };
-
-	      cmdarg_vec.push_back (cmdarg);
-	    }
+	    cmdarg_vec.emplace_back (CMDARG_FILE, optarg);
 	    break;
 	  case 'X':
-	    {
-	      struct cmdarg cmdarg = { CMDARG_COMMAND, optarg };
-
-	      cmdarg_vec.push_back (cmdarg);
-	    }
+	    cmdarg_vec.emplace_back (CMDARG_COMMAND, optarg);
 	    break;
 	  case OPT_IX:
-	    {
-	      struct cmdarg cmdarg = { CMDARG_INIT_FILE, optarg };
-
-	      cmdarg_vec.push_back (cmdarg);
-	    }
+	    cmdarg_vec.emplace_back (CMDARG_INIT_FILE, optarg);
 	    break;
 	  case OPT_IEX:
-	    {
-	      struct cmdarg cmdarg = { CMDARG_INIT_COMMAND, optarg };
-
-	      cmdarg_vec.push_back (cmdarg);
-	    }
+	    cmdarg_vec.emplace_back (CMDARG_INIT_COMMAND, optarg);
 	    break;
 	  case 'B':
 	    batch_flag = batch_silent = 1;
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 3d28606..2a40b16 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -919,7 +919,7 @@ collection_list::add_memrange (int type, bfd_signed_vma base,
   /* type: memrange_absolute == memory, other n == basereg */
   /* base: addr if memory, offset if reg relative.  */
   /* len: we actually save end (base + len) for convenience */
-  m_memranges.push_back (memrange (type, base, base + len));
+  m_memranges.emplace_back (type, base, base + len);
 
   if (type != memrange_absolute)    /* Better collect the base register!  */
     add_register (type);
-- 
2.5.5


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

end of thread, other threads:[~2016-11-09 18:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-09  0:39 [PATCH] gdb: Use vector::emplace_back Pedro Alves
2016-11-09 11:12 ` Yao Qi
2016-11-09 12:21   ` Pedro Alves
2016-11-09 12:43     ` Yao Qi
2016-11-09 12:55       ` Pedro Alves
2016-11-09 14:50         ` John Baldwin
2016-11-09 15:27           ` Pedro Alves
2016-11-09 17:08             ` John Baldwin
2016-11-09 18:45               ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox