From: Dodji Seketeli Date: Fri, 29 Sep 2017 11:20:35 +0000 (+0200) Subject: [abixml writer] Store pointers to emitted types rather than type-ids X-Git-Tag: libabigail-1.0~27 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=9135d990f514c79a6682ce52370c1462a329213e;p=libabigail.git [abixml writer] Store pointers to emitted types rather than type-ids To record the emitted types, the abixml writer records the emitted type *ID*s. So to lookup an emitted type, it needs to lookup the ID of the type first, and then lookup that type-id in the set of emitted type IDs. We are doing twice as much work as we should and profiling the writting of a big abixml showed that it's quite taxing. This patch makes the write records the set of emitted types directly. No need to go through the emitted type *ID*s anymore. So we save one map lookup. This incurs a 16% speedup when writting an abixml file for a big (3GB) vmlinux file. * src/abg-writer.cc (type_ptr_set_type): Declare new typedef. (writer_context::m_emitted_type_id_map): Remove this data member. (writer_context::m_emitted_type_set): Add a new data member. (writer_context::{record_type_id_as_emitted, type_id_is_emitted, clear_emitted_types_map}): Remove these member functions. (writer_context::{record_type_as_emitted, type_is_emitted}): Use the new m_emitted_type_set data member above. Signed-off-by: Dodji Seketeli --- diff --git a/src/abg-writer.cc b/src/abg-writer.cc index d04899c5..2e91be4f 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -144,6 +144,11 @@ typedef unordered_map type_ptr_map; +// A convenience typedef for a set of type_base*. +typedef unordered_set +type_ptr_set_type; + typedef unordered_map, string, function_tdecl::shared_ptr_hash> fn_tmpl_shared_ptr_map; @@ -160,9 +165,8 @@ class write_context ostream& m_ostream; bool m_annotate; mutable type_ptr_map m_type_id_map; - mutable unordered_map m_emitted_type_id_map; type_ptr_map m_emitted_decl_only_map; + mutable type_ptr_set_type m_emitted_type_set; // A map of types that are referenced by emitted pointers, // references or typedefs type_ptr_map m_referenced_types_map; @@ -297,17 +301,6 @@ public: clear_type_id_map() {m_type_id_map.clear();} - /// Record a given type id as belonging to a type that as been - /// written out to the XML output. - /// - /// @param id the ID of the type. - void - record_type_id_as_emitted(const string& id) - { - const environment* env = get_environment(); - assert(env); - m_emitted_type_id_map[env->intern(id)] = true; - } /// Getter of the map of types that were referenced by a pointer, /// reference or typedef. @@ -480,22 +473,25 @@ public: /// /// @param t the type to flag. void - record_type_as_emitted(const type_base_sptr& t) - { - string id = get_id_for_type(t); - record_type_id_as_emitted(id); - } + record_type_as_emitted(const type_base_sptr &t) + {record_type_as_emitted(t.get());} + + /// Flag a type as having been written out to the XML output. + /// + /// @param t the type to flag. + void + record_type_as_emitted(const type_base *t) + {m_emitted_type_set.insert(t);} - /// Test if a given type ID belongs to a type that has been written - /// out to the XML output. + /// Test if a given type has been written out to the XML output. /// - /// @param id the ID of the type to test. + /// @param the type to test for. /// /// @return true if the type has already been emitted, false /// otherwise. bool - type_id_is_emitted(const interned_string& id) - {return m_emitted_type_id_map.find(id) != m_emitted_type_id_map.end();} + type_is_emitted(const type_base *t) + {return m_emitted_type_set.find(t) != m_emitted_type_set.end();} /// Test if a given type has been written out to the XML output. /// @@ -505,12 +501,7 @@ public: /// otherwise. bool type_is_emitted(const type_base_sptr& t) - { - if (!type_has_existing_id(t)) - return false; - const interned_string& id = get_id_for_type(t); - return type_id_is_emitted(id); - } + {return type_is_emitted(t.get());} /// Test if the name of a given decl has been written out to the XML /// output. @@ -590,12 +581,6 @@ public: decl_only_type_is_emitted(const type_base_sptr& t) {return decl_only_type_is_emitted(t.get());} - /// Clear the map that contains the IDs of the types that has been - /// recorded as having been written out to the XML output. - void - clear_emitted_types_map() - {m_emitted_type_id_map.clear();} - /// Record a declaration as emitted in the abixml output. /// /// @param decl the decl to consider.