From: Simon Marchi Date: Thu, 24 Apr 2025 20:01:46 +0000 (-0400) Subject: gdb/dwarf: avoid cutu_reader moves X-Git-Tag: binutils-2_45~743 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=605b4e6f36615974635a17eed999c8ee34821e92;p=thirdparty%2Fbinutils-gdb.git gdb/dwarf: avoid cutu_reader moves 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 --- diff --git a/gdb/dwarf2/cooked-indexer.c b/gdb/dwarf2/cooked-indexer.c index 89cbdc6e975..5776dc5e956 100644 --- a/gdb/dwarf2/cooked-indexer.c +++ b/gdb/dwarf2/cooked-indexer.c @@ -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 (*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 (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 diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index e9cc542f8c9..aa830d402c4 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -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 (*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 (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 ()) diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index c69d8fbe5f1..5b4c8f673a0 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -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)