From patchwork Thu Sep 3 13:22:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 40358 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 134FE386102B; Thu, 3 Sep 2020 13:22:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 134FE386102B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599139340; bh=fV7omqMy/j+6s8/iz0i4sHHkzs0Oz1Xfe0gjbhOfrY4=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=qkP5Xg7sasa5DLXQeGlmxydVXb5OO3qnvrG27zfiSuYNqYkzIFvz3Nf/TU/oJsiDp 0vi5E9SpdFKyJvN24Lf+Ek63mK4eX2rW5GQ3q9s8LCiKOsiojfECH36eiW0bK9+iUQ QnmlYxIVVJvZH2pwZtuMbrdO1erN2tDssdFR0r7g= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by sourceware.org (Postfix) with ESMTPS id 6E4C93984FCD for ; Thu, 3 Sep 2020 13:22:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6E4C93984FCD Received: by mail-yb1-xb4a.google.com with SMTP id k74so2764331ybf.23 for ; Thu, 03 Sep 2020 06:22:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=fV7omqMy/j+6s8/iz0i4sHHkzs0Oz1Xfe0gjbhOfrY4=; b=Rq0cnW1W5thdGcZNSObUQNqjIiEXCPshyx9+Vdpcs4HOYVYn3ndEf53DRBo6hkk25J y3q6TjNMvUrAHbJkwJOsP6AKH8V7zm0Gx1t3PS3JNy02efCb6ijcE0xujZPko2201vGI 83qIOSOhlD0iBSy8j3L0jpVk9AIQ7OYswtY0B2sBsAPbuYi+0NhhSf1s/S7ezjgNUx4y kBQxQMCuFbsVMI72mvwAZdqlKMrmGfBq63inkbY06diRHuDrqANJ1u8/jY3EN4xQibL+ BElxTBO+rrtAkC/UhkwpymocExS1AR64AxQkPdPyFR4g37cXy1fktEcLHUB1aQ/CRaKQ 4SXw== X-Gm-Message-State: AOAM533g91/PbOUHxLfs9cuF1tyLimzV9YpvMt0jPmn1D4KVVLStW8Hx aB0AFAZPX71LM9yNe17nRApCsM/AojItEiylj+0RHiR7VSbE5AXHvWuWa6sIHJcmJOslcSSfCFx NR6GpPcBz055yahVSZpvNsm5WEd8oyh5RClfkZGok/VNEEQLQQpYxvPpNTgmYYg3Aqx536mY= X-Google-Smtp-Source: ABdhPJye2KShfa5bJlyWfoGpUhHu306w9IkjCMTIMcw8Y6u6W/6S0nwwpBVwJnDzkUuUNxUoGQFa8G4yU+ujjQ== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:110:a6ae:11ff:fe11:4f04]) (user=gprocida job=sendgmr) by 2002:a25:843:: with SMTP id 64mr2433340ybi.311.1599139336816; Thu, 03 Sep 2020 06:22:16 -0700 (PDT) Date: Thu, 3 Sep 2020 14:22:05 +0100 In-Reply-To: <20200903132205.589136-1-gprocida@google.com> Message-Id: <20200903132205.589136-4-gprocida@google.com> Mime-Version: 1.0 References: <20200903132205.589136-1-gprocida@google.com> X-Mailer: git-send-email 2.28.0.402.g5ffc5be6b7-goog Subject: [PATCH 3/3] Fix performance-unnecessary-copy-initialization warnings To: libabigail@sourceware.org X-Spam-Status: No, score=-22.4 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Giuliano Procida via Libabigail From: Giuliano Procida Reply-To: Giuliano Procida Cc: maennich@google.com, kernel-team@android.com Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" 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 --- 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()))