]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add m_builder member to lnp_state_machine
authorTom Tromey <tom@tromey.com>
Sat, 6 Sep 2025 19:17:18 +0000 (13:17 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 9 Sep 2025 00:52:48 +0000 (18:52 -0600)
I noticed that several spots in lnp_state_machine fetch the CU's
builder.  Since this can't change over the lifetime of the object, it
seemed nicer to simply cache it.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/dwarf2/line-program.c

index ac8b1772b6bc91d21372f769d042e21826e64c11..e70d7d3d1bc8e97c341e064e59c3af72a44894df 100644 (file)
@@ -154,6 +154,9 @@ private:
 
   struct dwarf2_cu *m_cu;
 
+  /* The builder associated with the CU.  */
+  buildsym_compunit *m_builder;
+
   gdbarch *m_gdbarch;
 
   /* The line number header.  */
@@ -296,7 +299,7 @@ lnp_state_machine::handle_const_add_pc ()
 bool
 lnp_state_machine::record_line_p ()
 {
-  if (m_cu->get_builder ()->get_current_subfile () != m_last_subfile)
+  if (m_builder->get_current_subfile () != m_last_subfile)
     return true;
   if (m_line != m_last_line)
     return true;
@@ -397,8 +400,7 @@ lnp_state_machine::record_line (bool end_sequence)
         when switching files, if we have seen a stmt at the current
         address, and we are switching to create a non-stmt line, then
         discard the new line.  */
-      bool file_changed
-       = m_last_subfile != m_cu->get_builder ()->get_current_subfile ();
+      bool file_changed = m_last_subfile != m_builder->get_current_subfile ();
       bool ignore_this_line
        = ((file_changed && !end_sequence && m_last_address == m_address
            && ((m_flags & LEF_IS_STMT) == 0)
@@ -419,13 +421,12 @@ lnp_state_machine::record_line (bool end_sequence)
 
          if (record_line_p ())
            {
-             buildsym_compunit *builder = m_cu->get_builder ();
              dwarf_record_line_1 (m_gdbarch,
-                                  builder->get_current_subfile (),
+                                  m_builder->get_current_subfile (),
                                   m_line, m_address, lte_flags,
                                   m_currently_recording_lines ? m_cu : nullptr);
 
-             m_last_subfile = m_cu->get_builder ()->get_current_subfile ();
+             m_last_subfile = m_builder->get_current_subfile ();
              m_last_line = m_line;
            }
        }
@@ -444,6 +445,7 @@ lnp_state_machine::record_line (bool end_sequence)
 lnp_state_machine::lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch,
                                      line_header *lh)
   : m_cu (cu),
+    m_builder (cu->get_builder ()),
     m_gdbarch (arch),
     m_line_header (lh),
     /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as