[PATCH] XML writer: adjust tracking of emitted declarations

Matthias Maennich maennich@google.com
Wed Nov 24 15:44:12 GMT 2021


Replace the std::unordered_map used to track emitted declarations with a
std::unordered_set as the map only ever held "true". The container
itself does not need to be marked mutable because record_decl_as_emitted
is called in a non-const context and can itself be made non-const. In
addition, the method decl_is_emitted calls a helper which no longer used
anywhere else and can be inlined. The remaining two methods are always
called on non-type declarations, so the test that existed in
decl_is_emitted can be dropped.

	* abg-writer.cc (write_context): Replace mutable
	m_emitted_decls_map with plain m_emitted_decls_set.
	(decl_name_is_emitted): Inlined into decl_is_emitted; dropped.
	(decl_is_emitted): Drop is_type check and inline
	decl_name_is_emitted. Look up in set instead of map.
	(record_decl_as_emitted): Make non-const. Insert into set
	instead of map.

Reviewed-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
---
 src/abg-writer.cc | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)

diff --git a/src/abg-writer.cc b/src/abg-writer.cc
index 693f99c6528d..f7efd671a485 100644
--- a/src/abg-writer.cc
+++ b/src/abg-writer.cc
@@ -168,9 +168,7 @@ class write_context
   class_tmpl_shared_ptr_map		m_class_tmpl_id_map;
   string_elf_symbol_sptr_map_type	m_fun_symbol_map;
   string_elf_symbol_sptr_map_type	m_var_symbol_map;
-  mutable unordered_map<interned_string,
-			bool,
-			hash_interned_string> m_emitted_decls_map;
+  unordered_set<interned_string, hash_interned_string> m_emitted_decls_set;
 
   write_context();
 
@@ -747,17 +745,6 @@ public:
   type_is_emitted(const type_base_sptr& t) const
   {return type_is_emitted(t.get());}
 
-  /// Test if the name of a given decl has been written out to the XML
-  /// output.
-  ///
-  /// @param the decl to consider.
-  ///
-  /// @return true if the decl has already been emitted, false
-  /// otherwise.
-  bool
-  decl_name_is_emitted(const interned_string& name) const
-  {return m_emitted_decls_map.find(name) != m_emitted_decls_map.end();}
-
   /// Test if a given decl has been written out to the XML output.
   ///
   /// @param the decl to consider.
@@ -767,13 +754,9 @@ public:
   bool
   decl_is_emitted(decl_base_sptr& decl) const
   {
-    if (is_type(decl))
-      return false;
-
     string repr = get_pretty_representation(decl, true);
     interned_string irepr = decl->get_environment()->intern(repr);
-    bool is_emitted = decl_name_is_emitted(irepr);
-    return is_emitted;
+    return m_emitted_decls_set.find(irepr) != m_emitted_decls_set.end();
   }
 
   /// Record a declaration-only class as being emitted.
@@ -829,11 +812,11 @@ public:
   ///
   /// @param decl the decl to consider.
   void
-  record_decl_as_emitted(const decl_base_sptr &decl)const
+  record_decl_as_emitted(const decl_base_sptr& decl)
   {
     string repr = get_pretty_representation(decl, true);
     interned_string irepr = decl->get_environment()->intern(repr);
-    m_emitted_decls_map[irepr] = true;
+    m_emitted_decls_set.insert(irepr);
   }
 
   /// Get the set of types that have been emitted.
-- 
2.34.0.rc2.393.gf8c9666880-goog



More information about the Libabigail mailing list