Re-write partial_die_info allocation in load_partial_dies
authorYao Qi <yao.qi@linaro.org>
Mon, 26 Feb 2018 15:38:00 +0000 (15:38 +0000)
committerYao Qi <yao.qi@linaro.org>
Mon, 26 Feb 2018 15:38:00 +0000 (15:38 +0000)
commitcd9983dd5f16803aa60e9fe1692b7e6716ac3927
tree95f270d2de9aecfb9f60455a5501ddeb87535ee9
parentf46cd62a69b8050c7c30a53b29a781a9b5e9f062
Re-write partial_die_info allocation in load_partial_dies

load_partial_dies has a "while (1)" loop to visit each die, and create
partial_die_info if needed in each iteration, like this,

  part_die = XOBNEW (&cu->comp_unit_obstack, struct partial_die_info);

  while (1)
   {
      if (foo1) continue;

      if (foo2) continue;

      read_partial_die (, , part_die, ,);

      ....
      part_die = XOBNEW (&cu->comp_unit_obstack, struct partial_die_info);
   };

the code was written in a way that spaces are allocated on necessary on
cu->comp_unit_obstack.  I want to class-fy partial_die_info, but
partial_die_info ctor can't follow XOBNEW immediately, so this patch
rewrite this loop to:

  while (1)
   {
      if (foo1) continue;

      if (foo2) continue;

      struct partial_die_info pdi;
      read_partial_die (, , &pdi, ,);

      part_die = XOBNEW (&cu->comp_unit_obstack, struct partial_die_info);
      memcpy (part_die, &pdi, sizeof (pdi));
   };

we create a local variable pdi, if we need it, call XOBNEW, and copy.
This also reduce one XOBNEW call.  I measured the number of XOBNEW call in
load_partial_dies when gdb reads dwarf2read.o, without this patch, it is
18827, and with this patch, it is 18826.

gdb:

2018-026-26  Yao Qi  <yao.qi@linaro.org>

* dwarf2read.c (load_partial_dies): Move the location of XOBNEW.
gdb/ChangeLog
gdb/dwarf2read.c