]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: use ranged for loop in some pots
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 10 Mar 2025 18:40:59 +0000 (14:40 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 10 Mar 2025 20:09:02 +0000 (16:09 -0400)
I noticed that these loops could be written to avoid the iteration
variable `i`.

Change-Id: Ia3717acbbf732f0337870d35ac60fe6400383324

gdb/dwarf2/index-write.c
gdb/dwarf2/read.c

index 9d876b1b93c77f411555e307ee6fce3868abe185..8fb59318538ef7a9971d2469435bca9206c1c0d6 100644 (file)
@@ -1317,11 +1317,9 @@ write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index *table,
      work here.  */
 
   int counter = 0;
-  for (int i = 0; i < per_bfd->all_units.size (); ++i)
+  for (const dwarf2_per_cu_up &per_cu : per_bfd->all_units)
     {
-      dwarf2_per_cu *per_cu = per_bfd->all_units[i].get ();
-
-      const auto insertpair = cu_index_htab.emplace (per_cu, counter);
+      const auto insertpair = cu_index_htab.emplace (per_cu.get (), counter);
       gdb_assert (insertpair.second);
 
       /* See enhancement PR symtab/30838.  */
@@ -1337,7 +1335,7 @@ write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index *table,
                           to_underlying (per_cu->sect_off));
       if (per_cu->is_debug_types)
        {
-         signatured_type *sig_type = (signatured_type *) per_cu;
+         signatured_type *sig_type = (signatured_type *) per_cu.get ();
          cu_list.append_uint (8, BFD_ENDIAN_LITTLE,
                               to_underlying (sig_type->type_offset_in_tu));
          cu_list.append_uint (8, BFD_ENDIAN_LITTLE,
@@ -1400,14 +1398,12 @@ write_debug_names (dwarf2_per_bfd *per_bfd, cooked_index *table,
   debug_names nametable (per_bfd, dwarf5_is_dwarf64, dwarf5_byte_order);
   int counter = 0;
   int types_counter = 0;
-  for (int i = 0; i < per_bfd->all_units.size (); ++i)
+  for (const dwarf2_per_cu_up &per_cu : per_bfd->all_units)
     {
-      dwarf2_per_cu *per_cu = per_bfd->all_units[i].get ();
-
       int &this_counter = per_cu->is_debug_types ? types_counter : counter;
       data_buf &this_list = per_cu->is_debug_types ? types_cu_list : cu_list;
 
-      nametable.add_cu (per_cu, this_counter);
+      nametable.add_cu (per_cu.get (), this_counter);
       this_list.append_uint (nametable.dwarf5_offset_size (),
                             dwarf5_byte_order,
                             to_underlying (per_cu->sect_off));
index a25daa36d38caca8f5651ea7bc0a1b4d94b492a7..c8c2ecd645941fce70dabc47315084f2adb0452b 100644 (file)
@@ -1968,16 +1968,14 @@ dwarf2_base_index_functions::expand_all_symtabs (struct objfile *objfile)
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
   int total_units = per_objfile->per_bfd->all_units.size ();
 
-  for (int i = 0; i < total_units; ++i)
+  for (const dwarf2_per_cu_up &per_cu : per_objfile->per_bfd->all_units)
     {
-      dwarf2_per_cu *per_cu = per_objfile->per_bfd->get_cu (i);
-
       /* We don't want to directly expand a partial CU, because if we
         read it with the wrong language, then assertion failures can
         be triggered later on.  See PR symtab/23010.  So, tell
         dw2_instantiate_symtab to skip partial CUs -- any important
         partial CU will be read via DW_TAG_imported_unit anyway.  */
-      dw2_instantiate_symtab (per_cu, per_objfile, true);
+      dw2_instantiate_symtab (per_cu.get (), per_objfile, true);
     }
 }