]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: avoid cutu_reader moves
authorSimon Marchi <simon.marchi@polymtl.ca>
Thu, 24 Apr 2025 20:01:46 +0000 (16:01 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 29 Apr 2025 19:54:13 +0000 (15:54 -0400)
In process_psymtab_comp_unit and ensure_cu_exists, we create a temporary
cutu_reader on the stack, then move it to a heap allocated cutu_reader
once we confirmed the unit is not dummy.  I think it's unnecessary to
create a temporary cutu_reader.  The only downside of not doing so is that if it
ends up that the CU is dummy, we made an allocation/deallocation for
nothing.  Dummy CUs are a rare thing, it shouldn't change anything.

This allows removing the cutu_reader move constructor.

Change-Id: I44742d471c495055ee46db41c0e7bdfbd2d5c0b7
Approved-By: Tom Tromey <tom@tromey.com>
gdb/dwarf2/cooked-indexer.c
gdb/dwarf2/read.c
gdb/dwarf2/read.h

index 89cbdc6e975d7415efc0b0e227eabd1b57e35e60..5776dc5e9562287d9b0ab7e348cb7cc9ec4af1ac 100644 (file)
@@ -109,16 +109,18 @@ cooked_indexer::ensure_cu_exists (cutu_reader *reader,
   cutu_reader *result = m_index_storage->get_reader (per_cu);
   if (result == nullptr)
     {
-      cutu_reader new_reader (*per_cu, *per_objfile, nullptr, nullptr, false,
-                             language_minimal,
-                             &m_index_storage->get_abbrev_table_cache ());
-
-      if (new_reader.is_dummy () || new_reader.top_level_die () == nullptr
-         || !new_reader.top_level_die ()->has_children)
+      const abbrev_table_cache &abbrev_table_cache
+       = m_index_storage->get_abbrev_table_cache ();
+      auto new_reader
+       = std::make_unique<cutu_reader> (*per_cu, *per_objfile, nullptr,
+                                        nullptr, false, language_minimal,
+                                        &abbrev_table_cache);
+
+      if (new_reader->is_dummy () || new_reader->top_level_die () == nullptr
+         || !new_reader->top_level_die ()->has_children)
        return nullptr;
 
-      auto copy = std::make_unique<cutu_reader> (std::move (new_reader));
-      result = m_index_storage->preserve (std::move (copy));
+      result = m_index_storage->preserve (std::move (new_reader));
     }
 
   if (result->is_dummy () || result->top_level_die () == nullptr
index e9cc542f8c99378f5746708a79540a8c6a24f6ed..aa830d402c4f04e66885c07a033181a7961b9e2e 100644 (file)
@@ -3196,15 +3196,17 @@ process_psymtab_comp_unit (dwarf2_per_cu *this_cu,
   cutu_reader *reader = storage->get_reader (this_cu);
   if (reader == nullptr)
     {
-      cutu_reader new_reader (*this_cu, *per_objfile, nullptr, nullptr, false,
-                             language_minimal,
-                             &storage->get_abbrev_table_cache ());
-
-      if (new_reader.cu () == nullptr || new_reader.is_dummy ())
+      const abbrev_table_cache &abbrev_table_cache
+       = storage->get_abbrev_table_cache ();
+      auto new_reader = std::make_unique<cutu_reader> (*this_cu, *per_objfile,
+                                                      nullptr, nullptr, false,
+                                                      language_minimal,
+                                                      &abbrev_table_cache);
+
+      if (new_reader->cu () == nullptr || new_reader->is_dummy ())
        return;
 
-      auto copy = std::make_unique<cutu_reader> (std::move (new_reader));
-      reader = storage->preserve (std::move (copy));
+      reader = storage->preserve (std::move (new_reader));
     }
 
   if (reader->top_level_die () == nullptr || reader->is_dummy ())
index c69d8fbe5f1a8fcb2da03e6f61bcca7d65c142b7..5b4c8f673a0f0b01edf929749f8cb9a8af9e3e88 100644 (file)
@@ -934,8 +934,6 @@ public:
 
   DISABLE_COPY_AND_ASSIGN (cutu_reader);
 
-  cutu_reader (cutu_reader &&) = default;
-
   /* Return true if either:
 
       - the unit is empty (just a header without any DIE)