public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] XML writer: adjust tracking of emitted declarations
@ 2021-11-24 15:44 Matthias Maennich
  2021-11-29  9:00 ` Dodji Seketeli
  0 siblings, 1 reply; 2+ messages in thread
From: Matthias Maennich @ 2021-11-24 15:44 UTC (permalink / raw)
  To: libabigail; +Cc: dodji, gprocida, kernel-team, maennich

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] XML writer: adjust tracking of emitted declarations
  2021-11-24 15:44 [PATCH] XML writer: adjust tracking of emitted declarations Matthias Maennich
@ 2021-11-29  9:00 ` Dodji Seketeli
  0 siblings, 0 replies; 2+ messages in thread
From: Dodji Seketeli @ 2021-11-29  9:00 UTC (permalink / raw)
  To: Matthias Maennich; +Cc: libabigail, gprocida, kernel-team

Hello,

Matthias Maennich <maennich@google.com> a écrit:

[...]
>    decl_is_emitted(decl_base_sptr& decl) const
>    {
> -    if (is_type(decl))
> -      return false;
> -

Rather than dropping this test, I have turned it into an assert.

[...]


> 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>

Applied the amended version to master. Thanks!

I am attaching the committed patch below.

Cheers,

From ce38bd24cd20561c7ebb12e615ba9457feab9e8f Mon Sep 17 00:00:00 2001
From: Matthias Maennich <maennich@google.com>
Date: Wed, 24 Nov 2021 15:44:12 +0000
Subject: [PATCH] XML writer: adjust tracking of emitted declarations

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): Turn the is_type check into an assert 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>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
---
 src/abg-writer.cc | 26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)

diff --git a/src/abg-writer.cc b/src/abg-writer.cc
index 693f99c6..21b79e88 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,10 @@ public:
   bool
   decl_is_emitted(decl_base_sptr& decl) const
   {
-    if (is_type(decl))
-      return false;
-
+    ABG_ASSERT(!is_type(decl));
     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 +813,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.33.1



-- 
		Dodji

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-29  9:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-24 15:44 [PATCH] XML writer: adjust tracking of emitted declarations Matthias Maennich
2021-11-29  9:00 ` Dodji Seketeli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).