public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] abg-dwarf-reader: simplify symbol map update
@ 2020-04-20  7:43 Matthias Maennich
  2020-04-20  8:11 ` Giuliano Procida
  2020-04-20 12:53 ` Dodji Seketeli
  0 siblings, 2 replies; 3+ messages in thread
From: Matthias Maennich @ 2020-04-20  7:43 UTC (permalink / raw)
  To: libabigail; +Cc: dodji, gprocida, kernel-team, maennich

For the update of fun_syms_, undefined_fun_syms_, var_syms_,
undefined_var_syms_, there is a pattern in
read_context::load_symbol_maps_from_symtab_section that can be
simplified: We try to find the correct entry and keep the iterator. If
we do not find it, we construct the value vector, find it again and
update the iterator. Eventually we push_back the symbol. That can be
simplified to looking up the value with operator[], which either returns
the existing value or default constructs it. The reference returned is
good for the push_back in any case.

	* src/abg-dwarf-reader.cc
	(read_context::load_symbol_maps_from_symtab_section): simplify
	symbol map update for fun_syms_, undefined_fun_syms_, var_syms_,
	undefined_var_syms_.

Signed-off-by: Matthias Maennich <maennich@google.com>
---
 src/abg-dwarf-reader.cc | 46 ++++-------------------------------------
 1 file changed, 4 insertions(+), 42 deletions(-)

diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index 333bab909901..1c0d6ea0353f 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -7460,17 +7460,7 @@ public:
 
 	    if (load_fun_map && symbol->is_public())
 	      {
-		{
-		  string_elf_symbols_map_type::iterator it =
-		    fun_syms_->find(symbol->get_name());
-		  if (it == fun_syms_->end())
-		    {
-		      (*fun_syms_)[symbol->get_name()] = elf_symbols();
-		      it = fun_syms_->find(symbol->get_name());
-		    }
-		  string name = symbol->get_name();
-		  it->second.push_back(symbol);
-		}
+		(*fun_syms_)[symbol->get_name()].push_back(symbol);
 
 		{
 		  GElf_Addr symbol_value =
@@ -7572,16 +7562,7 @@ public:
 		}
 	      }
 	    else if (load_undefined_fun_map && !symbol->is_defined())
-	      {
-		string_elf_symbols_map_type::iterator it =
-		  undefined_fun_syms_->find(symbol->get_name());
-		if (it == undefined_fun_syms_->end())
-		  {
-		    (*undefined_fun_syms_)[symbol->get_name()] = elf_symbols();
-		    it = undefined_fun_syms_->find(symbol->get_name());
-		  }
-		it->second.push_back(symbol);
-	      }
+	      (*undefined_fun_syms_)[symbol->get_name()].push_back(symbol);
 	  }
 	else if ((load_var_map || load_undefined_var_map)
 		 && (GELF_ST_TYPE(sym->st_info) == STT_OBJECT
@@ -7598,17 +7579,7 @@ public:
 
 	    if (load_var_map && symbol->is_public())
 	      {
-		{
-		  string_elf_symbols_map_type::iterator it =
-		    var_syms_->find(symbol->get_name());
-		  if (it == var_syms_->end())
-		    {
-		      (*var_syms_)[symbol->get_name()] = elf_symbols();
-		      it = var_syms_->find(symbol->get_name());
-		    }
-		  string name = symbol->get_name();
-		  it->second.push_back(symbol);
-		}
+		(*var_syms_)[symbol->get_name()].push_back(symbol);
 
 		if (symbol->is_common_symbol())
 		  {
@@ -7641,16 +7612,7 @@ public:
 		  }
 	      }
 	    else if (load_undefined_var_map && !symbol->is_defined())
-	      {
-		string_elf_symbols_map_type::iterator it =
-		  undefined_var_syms_->find(symbol->get_name());
-		if (it == undefined_var_syms_->end())
-		  {
-		    (*undefined_var_syms_)[symbol->get_name()] = elf_symbols();
-		    it = undefined_var_syms_->find(symbol->get_name());
-		  }
-		it->second.push_back(symbol);
-	      }
+	      (*undefined_var_syms_)[symbol->get_name()].push_back(symbol);
 	  }
       }
     return true;
-- 
2.26.1.301.g55bc3eb7cb9-goog


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-20 12:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-20  7:43 [PATCH] abg-dwarf-reader: simplify symbol map update Matthias Maennich
2020-04-20  8:11 ` Giuliano Procida
2020-04-20 12:53 ` Dodji Seketeli

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