Speed up class_decl::find_base_class
authorDodji Seketeli <dodji@redhat.com>
Mon, 4 Jan 2016 14:36:54 +0000 (15:36 +0100)
committerDodji Seketeli <dodji@redhat.com>
Mon, 4 Jan 2016 18:58:01 +0000 (19:58 +0100)
This is useful for big debug info data set.  Also, this function is
going to be used extensively in subsequent patch that fixes a base
class representation related issue.

* src/abg-ir.cc (class_decl::priv::bases_map_): New data member.
(class_decl::add_base_specifier): Add the new base specifier to
the new class_decl::priv::bases_map_ data member.
(class_decl::find_base_class): Use the new
class_decl::priv::bases_map_ data member to speed up finding the
base class.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
src/abg-ir.cc

index 34830d5..24e8d9d 100644 (file)
@@ -10593,6 +10593,7 @@ struct class_decl::priv
   decl_base_sptr               declaration_;
   class_decl_sptr              definition_of_declaration_;
   base_specs                   bases_;
+  unordered_map<string, base_spec_sptr>        bases_map_;
   member_types                 member_types_;
   data_members                 data_members_;
   data_members                 non_static_data_members_;
@@ -10946,6 +10947,7 @@ void
 class_decl::add_base_specifier(base_spec_sptr b)
 {
   priv_->bases_.push_back(b);
+  priv_->bases_map_[b->get_base_class()->get_qualified_name()] = b;
   assert(!b->get_environment());
   if (environment* env = get_environment())
     b->set_environment(env);
@@ -10967,12 +10969,11 @@ class_decl::get_base_specifiers() const
 class_decl_sptr
 class_decl::find_base_class(const string& qualified_name) const
 {
-  for (base_specs::const_iterator i = get_base_specifiers().begin();
-       i != get_base_specifiers().end();
-       ++i)
-    if ((*i)->get_base_class()->get_qualified_name()
-       == qualified_name)
-      return (*i)->get_base_class();
+  unordered_map<string, base_spec_sptr>::iterator i =
+    priv_->bases_map_.find(qualified_name);
+
+  if (i != priv_->bases_map_.end())
+    return i->second->get_base_class();
 
   return class_decl_sptr();
 }