From: Matthias Maennich <maennich@google.com>
To: libabigail@sourceware.org
Cc: dodji@seketeli.org, gprocida@google.com, kernel-team@android.com,
maennich@google.com
Subject: [PATCH] XML writer: adjust tracking of emitted declarations
Date: Wed, 24 Nov 2021 15:44:12 +0000 [thread overview]
Message-ID: <20211124154411.2434715-1-maennich@google.com> (raw)
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
next reply other threads:[~2021-11-24 15:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-24 15:44 Matthias Maennich [this message]
2021-11-29 9:00 ` Dodji Seketeli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211124154411.2434715-1-maennich@google.com \
--to=maennich@google.com \
--cc=dodji@seketeli.org \
--cc=gprocida@google.com \
--cc=kernel-team@android.com \
--cc=libabigail@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).