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>
This commit is contained in:
Matthias Maennich 2021-11-24 15:44:12 +00:00 committed by Dodji Seketeli
parent e6f3193b0b
commit ce38bd24cd
1 changed files with 5 additions and 21 deletions

View File

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