diff mbox series

abg-dwarf-reader: simplify symbol map update

Message ID 20200420074311.92426-1-maennich@google.com
State Committed
Headers show
Series abg-dwarf-reader: simplify symbol map update | expand

Commit Message

Matthias Maennich April 20, 2020, 7:43 a.m. UTC
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(-)

Comments

Giuliano Procida April 20, 2020, 8:11 a.m. UTC | #1
This looks good to me.

Giuliano.

On Mon, 20 Apr 2020 at 08:43, 'Matthias Maennich' via kernel-team
<kernel-team@android.com> wrote:
>
> 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_.
>

Reviewed-by: Giuliano Procida <gprocida@google.com>

> 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
>
> --
> To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com.
>
Dodji Seketeli April 20, 2020, 12:53 p.m. UTC | #2
Matthias Maennich <maennich@google.com> a ?crit:

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

Applied to master, thanks!


Cheers,
diff mbox series

Patch

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;