public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: Giuliano Procida <gprocida@google.com>
To: libabigail@sourceware.org
Cc: dodji@seketeli.org, kernel-team@android.com, gprocida@google.com,
	 maennich@google.com
Subject: [PATCH 3/3] Fix performance-unnecessary-copy-initialization warnings
Date: Thu,  3 Sep 2020 14:22:05 +0100	[thread overview]
Message-ID: <20200903132205.589136-4-gprocida@google.com> (raw)
In-Reply-To: <20200903132205.589136-1-gprocida@google.com>

clang-tidy's performance-unnecessary-copy-initialization warning is
triggered when it detects unncessary copying of objects. In the case
of the shared_ptr types used by libabigail, the extra cost is
primarily that of manipulating reference counts.

This commit addresses these warnings. Note that while they are
unlikely to be genuine performance issues, eliminating them means
we'll be able to spot new issues more easily.

	* include/abg-diff-utils.h (compute_diff): Take const
	reference to point instead of copying.
	* src/abg-comparison-priv.h (elf_symbol_comp::operator()):
	Take const references to strings instead of copying.
	* src/abg-default-reporter.cc (default_reporter::report): Take
	const references to diff_sptrs instead of copying.
	* src/abg-dwarf-reader.cc (die_location): Take a const
	reference to translation_unit_sptr instead of copying.
	* src/abg-ir.cc (function_decls_alias): Take const references
	to elf_symbol_sptrs instead of copying.
	(virtual_member_function_less_than::operator()): Take const
	reference to location instead of copying.
	(methods_equal_modulo_elf_symbol): Modify objects through
	given shared pointers rather than copies thereof.
	* src/abg-suppression.cc
	(function_suppression::suppresses_function): Take const
	references to elf_symbol_sptrs instead of copying them.
	* tools/abipkgdiff.cc (create_private_types_suppressions):
	Take const reference to package_sptr instead of copying.

Signed-off-by: Giuliano Procida <gprocida@google.com>
---
 include/abg-diff-utils.h    |  2 +-
 src/abg-comparison-priv.h   |  3 ++-
 src/abg-default-reporter.cc |  4 ++--
 src/abg-dwarf-reader.cc     |  2 +-
 src/abg-ir.cc               | 11 ++++++-----
 src/abg-suppression.cc      |  8 ++++----
 tools/abipkgdiff.cc         |  2 +-
 7 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/include/abg-diff-utils.h b/include/abg-diff-utils.h
index b59ffa04f..d113e8380 100644
--- a/include/abg-diff-utils.h
+++ b/include/abg-diff-utils.h
@@ -1623,7 +1623,7 @@ compute_diff(RandomAccessOutputIterator a_base,
 
       if (snak.has_vertical_edge())
 	{
-	  point p = snak.intermediate();
+	  const point& p = snak.intermediate();
 	  insertion ins(p.x());
 	  ins.inserted_indexes().push_back(p.y());
 	  ses.insertions().push_back(ins);
diff --git a/src/abg-comparison-priv.h b/src/abg-comparison-priv.h
index b82b5d070..8e17155fd 100644
--- a/src/abg-comparison-priv.h
+++ b/src/abg-comparison-priv.h
@@ -981,7 +981,8 @@ struct elf_symbol_comp
   bool
   operator()(const elf_symbol& l, const elf_symbol& r)
   {
-    string name1 = l.get_id_string(), name2 = r.get_id_string();
+    const string& name1 = l.get_id_string();
+    const string& name2 = r.get_id_string();
     return name1 < name2;
   }
 
diff --git a/src/abg-default-reporter.cc b/src/abg-default-reporter.cc
index f8572f25c..03c1137fd 100644
--- a/src/abg-default-reporter.cc
+++ b/src/abg-default-reporter.cc
@@ -489,7 +489,7 @@ default_reporter::report(const reference_diff& d, ostream& out,
     report_local_reference_type_changes(d, out, indent);
 
   if (k & SUBTYPE_CHANGE_KIND)
-    if (diff_sptr dif = d.underlying_type_diff())
+    if (const diff_sptr& dif = d.underlying_type_diff())
       {
 	RETURN_IF_BEING_REPORTED_OR_WAS_REPORTED_EARLIER2(dif,
 							  "referenced type");
@@ -680,7 +680,7 @@ default_reporter::report(const array_diff& d, ostream& out,
 						    d.second_array(),
 						    "array type");
 
-  diff_sptr dif = d.element_type_diff();
+  const diff_sptr& dif = d.element_type_diff();
   if (dif->to_be_reported())
     {
       string fn = ir::get_pretty_representation(is_type(dif->first_subject()));
diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index 7c56bd8c4..88d775b99 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -8426,7 +8426,7 @@ die_location(const read_context& ctxt, const Dwarf_Die* die)
 
   if (!file.empty() && line != 0)
     {
-      translation_unit_sptr tu = ctxt.cur_transl_unit();
+      const translation_unit_sptr& tu = ctxt.cur_transl_unit();
       location l = tu->get_loc_mgr().create_new_location(file, line, 1);
       return l;
     }
diff --git a/src/abg-ir.cc b/src/abg-ir.cc
index 358a7a26a..68afd6ea1 100644
--- a/src/abg-ir.cc
+++ b/src/abg-ir.cc
@@ -17746,7 +17746,8 @@ function_decl::get_id() const
 bool
 function_decls_alias(const function_decl& f1, const function_decl& f2)
 {
-  elf_symbol_sptr s1 = f1.get_symbol(), s2 = f2.get_symbol();
+  const elf_symbol_sptr& s1 = f1.get_symbol();
+  const elf_symbol_sptr& s2 = f2.get_symbol();
 
   if (!s1 || !s2)
     return false;
@@ -20490,7 +20491,8 @@ struct virtual_member_function_less_than
 	  {
 	    string fn_filepath, sn_filepath;
 	    unsigned line = 0, column = 0;
-	    location fn_loc = f.get_location(), sn_loc = s.get_location();
+	    const location& fn_loc = f.get_location();
+	    const location& sn_loc = s.get_location();
 	    if (fn_loc)
 	      fn_loc.expand(fn_filepath, line, column);
 	    if (sn_loc)
@@ -20710,10 +20712,9 @@ class_decl::get_hash() const
 /// @return true iff @p f equals @p s without taking their linkage
 /// name or symbol into account.
 static bool
-methods_equal_modulo_elf_symbol(const method_decl_sptr& f,
-				const method_decl_sptr& s)
+methods_equal_modulo_elf_symbol(const method_decl_sptr& first,
+				const method_decl_sptr& second)
 {
-  method_decl_sptr first = f, second = s;
   elf_symbol_sptr saved_first_elf_symbol =
     first->get_symbol();
   elf_symbol_sptr saved_second_elf_symbol =
diff --git a/src/abg-suppression.cc b/src/abg-suppression.cc
index ae7cc95ce..d6ee9dc56 100644
--- a/src/abg-suppression.cc
+++ b/src/abg-suppression.cc
@@ -2500,7 +2500,7 @@ function_suppression::suppresses_function(const function_decl* fn,
 	  // function only if the suppression condition matches the
 	  // names of all aliases.
 	  string symbol_name;
-	  elf_symbol_sptr sym = fn->get_symbol();
+	  const elf_symbol_sptr& sym = fn->get_symbol();
 	  ABG_ASSERT(sym);
 	  symbol_name = sym->get_name();
 	  if (sym->has_aliases() && sym->get_alias_from_name(fname))
@@ -2534,7 +2534,7 @@ function_suppression::suppresses_function(const function_decl* fn,
 	  // function only if the suppression condition matches *all*
 	  // the aliases.
 	  string symbol_name;
-	  elf_symbol_sptr sym = fn->get_symbol();
+	  const elf_symbol_sptr& sym = fn->get_symbol();
 	  ABG_ASSERT(sym);
 	  symbol_name = sym->get_name();
 	  if (sym->has_aliases())
@@ -2565,7 +2565,7 @@ function_suppression::suppresses_function(const function_decl* fn,
 	  // function only if the suppression condition matches *all*
 	  // the aliases.
 	  string symbol_name;
-	  elf_symbol_sptr sym = fn->get_symbol();
+	  const elf_symbol_sptr& sym = fn->get_symbol();
 	  ABG_ASSERT(sym);
 	  symbol_name = sym->get_name();
 	  if (sym->has_aliases())
@@ -2604,7 +2604,7 @@ function_suppression::suppresses_function(const function_decl* fn,
   // Check if the "symbol_name", "symbol_name_regexp", and
   // "symbol_name_not_regexp" properties match.
   string fn_sym_name, fn_sym_version;
-  elf_symbol_sptr sym = fn->get_symbol();
+  const elf_symbol_sptr& sym = fn->get_symbol();
   if (sym)
     {
       fn_sym_name = sym->get_name();
diff --git a/tools/abipkgdiff.cc b/tools/abipkgdiff.cc
index 445e24068..c24868afd 100644
--- a/tools/abipkgdiff.cc
+++ b/tools/abipkgdiff.cc
@@ -1489,7 +1489,7 @@ create_private_types_suppressions(const package& pkg, const options &opts)
 {
   suppressions_type supprs;
 
-  package_sptr devel_pkg = pkg.devel_package();
+  const package_sptr& devel_pkg = pkg.devel_package();
   if (!devel_pkg
       || !file_exists(devel_pkg->extracted_dir_path())
       || !is_dir(devel_pkg->extracted_dir_path()))
-- 
2.28.0.402.g5ffc5be6b7-goog


      parent reply	other threads:[~2020-09-03 13:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-03 13:22 [PATCH 0/3] clang-tidy error and warning fixes Giuliano Procida
2020-09-03 13:22 ` [PATCH 1/3] abg-corpus-priv.h: include abg-corpus.h Giuliano Procida
2020-09-03 13:22 ` [PATCH 2/3] Fix readability-redundant-smartptr-get warnings Giuliano Procida
2020-09-03 13:22 ` Giuliano Procida [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200903132205.589136-4-gprocida@google.com \
    --to=gprocida@google.com \
    --cc=dodji@seketeli.org \
    --cc=kernel-team@android.com \
    --cc=libabigail@sourceware.org \
    --cc=maennich@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).