gdb: Use vector::emplace_back
authorPedro Alves <palves@redhat.com>
Wed, 9 Nov 2016 14:53:58 +0000 (14:53 +0000)
committerPedro Alves <palves@redhat.com>
Wed, 9 Nov 2016 14:53:58 +0000 (14:53 +0000)
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:
2016-11-09  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/ChangeLog
gdb/main.c
gdb/tracepoint.c

index 2f0f3c2da44fcbb48e85a4edbe1aa1b1be664efa..4d16c38aa8f4ce8e9f6b0dd99b18724ee9fedcaa 100644 (file)
@@ -1,3 +1,9 @@
+2016-11-09  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.
+
 2016-11-09  Andreas Arnez  <arnez@linux.vnet.ibm.com>
 
        * tui/tui-winsource.c (tui_alloc_source_buffer): Remove
index ca6a81e804ae0569d21217d16ce668ab9be27d83..fe57bf8d44272b915e5f2ce2dc16e5999354a536 100644 (file)
@@ -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;
index 3d28606eab1b12edfacb80965b375282f2791efe..2a40b1675586544759d073d447b3c5324fe41793 100644 (file)
@@ -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);