[09/20] abg-reader: avoid using the (var|function)_symbol_map

Message ID 20210127125853.886677-10-maennich@google.com
State Committed
Headers
Series Refactor (k)symtab reader |

Commit Message

Matthias Männich Jan. 27, 2021, 12:58 p.m. UTC
  Instead of using the corpus var|function_symbol_maps for symbol lookups,
let build_elf_symbol_from_reference use the symtab::lookup_symbol
method. That leads to a shorter implementation and we can drop the
indicative parameter.

	* src/abg-reader.cc (build_elf_symbol_from_reference): drop
	  last parameter indicating the lookup type and use corpus
	  symtab for the lookup
	  (build_function_decl): Adjust accordingly.
	  (build_var_decl): Likewise.

Reviewed-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
---
 src/abg-reader.cc | 30 +++++++++---------------------
 1 file changed, 9 insertions(+), 21 deletions(-)
  

Comments

Dodji Seketeli March 15, 2021, 2:23 p.m. UTC | #1
Matthias Maennich <maennich@google.com> a écrit:

> Instead of using the corpus var|function_symbol_maps for symbol lookups,
> let build_elf_symbol_from_reference use the symtab::lookup_symbol
> method. That leads to a shorter implementation and we can drop the
> indicative parameter.
>
> 	* src/abg-reader.cc (build_elf_symbol_from_reference): drop
> 	  last parameter indicating the lookup type and use corpus
> 	  symtab for the lookup
> 	  (build_function_decl): Adjust accordingly.
> 	  (build_var_decl): Likewise.
>
> Reviewed-by: Giuliano Procida <gprocida@google.com>
> Signed-off-by: Matthias Maennich <maennich@google.com>

OK to apply to master once the pre-requisite patches are in.

Thanks!

[...]

Cheers,
  

Patch

diff --git a/src/abg-reader.cc b/src/abg-reader.cc
index 68b19cf4b65b..c26689ae17ca 100644
--- a/src/abg-reader.cc
+++ b/src/abg-reader.cc
@@ -1084,8 +1084,7 @@  static elf_symbol_sptr
 build_elf_symbol(read_context&, const xmlNodePtr, bool);
 
 static elf_symbol_sptr
-build_elf_symbol_from_reference(read_context&, const xmlNodePtr,
-				bool);
+build_elf_symbol_from_reference(read_context&, const xmlNodePtr);
 
 static string_elf_symbols_map_sptr
 build_elf_symbol_db(read_context&, const xmlNodePtr, bool);
@@ -2818,8 +2817,7 @@  build_elf_symbol(read_context& ctxt, const xmlNodePtr node,
 ///
 /// @return a shared pointer the resutling elf_symbol.
 static elf_symbol_sptr
-build_elf_symbol_from_reference(read_context& ctxt, const xmlNodePtr node,
-				bool function_symbol)
+build_elf_symbol_from_reference(read_context& ctxt, const xmlNodePtr node)
 {
   elf_symbol_sptr nil;
 
@@ -2838,20 +2836,12 @@  build_elf_symbol_from_reference(read_context& ctxt, const xmlNodePtr node,
       if (name.empty())
 	return nil;
 
-      string_elf_symbols_map_sptr sym_db =
-	(function_symbol)
-	? ctxt.get_corpus()->get_fun_symbol_map_sptr()
-	: ctxt.get_corpus()->get_var_symbol_map_sptr();
+      const elf_symbols& symbols =
+	  ctxt.get_corpus()->get_symtab()->lookup_symbol(name);
 
-      string_elf_symbols_map_type::const_iterator i = sym_db->find(name);
-      if (i != sym_db->end())
-	{
-	  for (elf_symbols::const_iterator s = i->second.begin();
-	       s != i->second.end();
-	       ++s)
-	    if ((*s)->get_id_string() == sym_id)
-	      return *s;
-	}
+      for (const auto& symbol : symbols)
+	if (symbol->get_id_string() == sym_id)
+	  return symbol;
     }
 
   return nil;
@@ -3102,8 +3092,7 @@  build_function_decl(read_context&	ctxt,
 
   ctxt.push_decl_to_current_scope(fn_decl, add_to_current_scope);
 
-  elf_symbol_sptr sym = build_elf_symbol_from_reference(ctxt, node,
-							/*function_sym=*/true);
+  elf_symbol_sptr sym = build_elf_symbol_from_reference(ctxt, node);
   if (sym)
     fn_decl->set_symbol(sym);
 
@@ -3334,8 +3323,7 @@  build_var_decl(read_context&	ctxt,
 				  locus, mangled_name,
 				  vis, bind));
 
-  elf_symbol_sptr sym = build_elf_symbol_from_reference(ctxt, node,
-							/*function_sym=*/false);
+  elf_symbol_sptr sym = build_elf_symbol_from_reference(ctxt, node);
   if (sym)
     decl->set_symbol(sym);