[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] "Sanitize" cppcheck's performance warnings
Cheers,
Ondrej
>From 2c84e163dcac85da0ebf2234a717799bd440510e Mon Sep 17 00:00:00 2001
From: Ondrej Oprala <ondrej.oprala@gmail.com>
Date: Wed, 12 Apr 2017 09:53:10 +0200
Subject: [PATCH 3/3] cppcheck: mitigate performance warnings
* include/abg-diff-utils.h (print_snake): pass argument of type
snake by const reference.
* include/abg-ir.h (location::operator{==,<}): Likewise.
* include/abg-viz-dot.h (node_base::{node_base,parent_node,child_node}):
Likewise.
* include/abg-viz-svg.h (svg::svg) Likewise.
* src/abg-config.cc (config::config): Member initialization in ctor body.
* src/abg-dwarf-reader.cc (class_decl_sptr::add_or_update_class_type):
Initial value never used.
* src/abg-ir.cc: (decl_base::priv::priv) Member initialization in ctor body,
pass argument of type location by const reference.
(equals): Variable initial value never used.
* src/abg-reader.cc (read_corpus_from_input): Initial variable
value never used.
(build_elf_symbol_db): Use pre-increment.
* src/abg-suppression-priv.h
(suppression_matches_type_location): Pass argument of type
location by const reference.
* src/abg-suppression.cc: Likewise.
Signed-off-by: Ondrej Oprala <ondrej.oprala@gmail.com>
---
include/abg-diff-utils.h | 2 +-
include/abg-ir.h | 4 ++--
include/abg-viz-dot.h | 8 ++++----
include/abg-viz-svg.h | 2 +-
src/abg-config.cc | 6 +++---
src/abg-dwarf-reader.cc | 3 +--
src/abg-ir.cc | 8 +++-----
src/abg-reader.cc | 5 ++---
src/abg-suppression-priv.h | 2 +-
src/abg-suppression.cc | 2 +-
10 files changed, 19 insertions(+), 23 deletions(-)
diff --git a/include/abg-diff-utils.h b/include/abg-diff-utils.h
index 716eb71..4aeadaf 100644
--- a/include/abg-diff-utils.h
+++ b/include/abg-diff-utils.h
@@ -1255,7 +1255,7 @@ template<typename RandomAccessOutputIterator>
void
print_snake(RandomAccessOutputIterator a_begin,
RandomAccessOutputIterator b_begin,
- const snake s, ostream& out)
+ const snake &s, ostream& out)
{
if (s.is_empty())
return;
diff --git a/include/abg-ir.h b/include/abg-ir.h
index d107d15..7e4c228 100644
--- a/include/abg-ir.h
+++ b/include/abg-ir.h
@@ -245,7 +245,7 @@ public:
///
/// @return true iff both locations are equal.
bool
- operator==(const location other) const
+ operator==(const location &other) const
{return value_ == other.value_;}
/// "Less than" operator of the @ref location type.
@@ -255,7 +255,7 @@ public:
/// @return true iff the current instance is less than the @p other
/// one.
bool
- operator<(const location other) const
+ operator<(const location &other) const
{return value_ < other.value_;}
/// Expand the current location into a tripplet file path, line and
diff --git a/include/abg-viz-dot.h b/include/abg-viz-dot.h
index 2f8a557..0182eda 100644
--- a/include/abg-viz-dot.h
+++ b/include/abg-viz-dot.h
@@ -43,7 +43,7 @@ struct node_base
const style& _M_style;
explicit
- node_base(std::string __id, type __t, const style& __sty)
+ node_base(const std::string& __id, type __t, const style& __sty)
: _M_id(__id), _M_count(++_M_count_total),
_M_type(__t), _M_x_space(0.4), _M_y_space(0.2), _M_style(__sty)
{ }
@@ -66,7 +66,7 @@ extern const style child_sty;
*/
struct parent_node : public node_base
{
- parent_node(std::string __id)
+ parent_node(const std::string& __id)
: node_base(__id, node_base::parent, parent_sty)
{ }
};
@@ -83,7 +83,7 @@ struct parent_node : public node_base
*/
struct child_node : public node_base
{
- child_node(std::string __id)
+ child_node(const std::string& __id)
: node_base(__id, node_base::child, child_sty)
{ }
};
@@ -118,7 +118,7 @@ private:
public:
- dot(const std::string __title,
+ dot(const std::string &__title,
const canvas& __cv = ansi_letter_canvas,
const typography& __typo = arial_typo)
: _M_title(__title), _M_canvas(__cv), _M_typo(__typo)
diff --git a/include/abg-viz-svg.h b/include/abg-viz-svg.h
index 033fa44..3a93594 100644
--- a/include/abg-viz-svg.h
+++ b/include/abg-viz-svg.h
@@ -99,7 +99,7 @@ private:
public:
- svg(const std::string __title,
+ svg(const std::string &__title,
const canvas& __cv = ansi_letter_canvas,
const typography& __typo = arial_typo)
: _M_title(__title), _M_canvas(__cv), _M_typo(__typo), _M_y_size(0)
diff --git a/src/abg-config.cc b/src/abg-config.cc
index 88e5465..8a7405b 100644
--- a/src/abg-config.cc
+++ b/src/abg-config.cc
@@ -35,10 +35,10 @@ namespace abigail
config::config()
: m_format_minor("0"),
m_format_major("1"),
- m_xml_element_indent(2)
+ m_xml_element_indent(2),
+ m_tu_instr_suffix(".bi"),
+ m_tu_instr_archive_suffix(".abi")
{
- m_tu_instr_suffix = ".bi" ;
- m_tu_instr_archive_suffix = ".abi";
}
const std::string&
diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index 9d7b841..f1029d3 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -11027,8 +11027,7 @@ add_or_update_class_type(read_context& ctxt,
continue;
int64_t offset_in_bits = 0;
- bool is_laid_out = false;
- is_laid_out = die_member_offset(&child, offset_in_bits);
+ bool is_laid_out = die_member_offset(&child, offset_in_bits);
// For now, is_static == !is_laid_out. When we have
// templates, we'll try to be more specific. For now,
// this approximation should do OK.
diff --git a/src/abg-ir.cc b/src/abg-ir.cc
index 5a84525..40338e5 100644
--- a/src/abg-ir.cc
+++ b/src/abg-ir.cc
@@ -2599,14 +2599,14 @@ struct decl_base::priv
location_(locus),
context_(),
name_(name),
+ qualified_name_(name),
linkage_name_(linkage_name),
visibility_(vis)
{
- qualified_name_ = name;
is_anonymous_ = name_.empty();
}
- priv(location l)
+ priv(const location& l)
: in_pub_sym_tab_(false),
is_anonymous_(true),
location_(l),
@@ -9959,9 +9959,7 @@ scope_type_decl::scope_type_decl(const environment* env,
bool
equals(const scope_type_decl& l, const scope_type_decl& r, change_kind* k)
{
- bool result = true;
-
- result = equals(static_cast<const scope_decl&>(l),
+ bool result = equals(static_cast<const scope_decl&>(l),
static_cast<const scope_decl&>(r),
k);
diff --git a/src/abg-reader.cc b/src/abg-reader.cc
index 2ae309b..99c1fc9 100644
--- a/src/abg-reader.cc
+++ b/src/abg-reader.cc
@@ -1768,10 +1768,9 @@ read_corpus_from_input(read_context& ctxt)
corp.set_needed(needed);
string_elf_symbols_map_sptr fn_sym_db, var_sym_db;
- bool is_ok = false;
// Read the symbol databases.
- is_ok = read_symbol_db_from_input(ctxt, fn_sym_db, var_sym_db);
+ bool is_ok = read_symbol_db_from_input(ctxt, fn_sym_db, var_sym_db);
if (is_ok)
{
assert(fn_sym_db || var_sym_db);
@@ -2556,7 +2555,7 @@ build_elf_symbol_db(read_context& ctxt,
while (std::getline(aliases, item, ','))
elems.push_back(item);
for (std::vector<string>::iterator alias = elems.begin();
- alias != elems.end(); alias++)
+ alias != elems.end(); ++alias)
{
string_elf_symbol_sptr_map_type::const_iterator i =
id_sym_map.find(*alias);
diff --git a/src/abg-suppression-priv.h b/src/abg-suppression-priv.h
index 9070223..39614c2 100644
--- a/src/abg-suppression-priv.h
+++ b/src/abg-suppression-priv.h
@@ -774,7 +774,7 @@ suppression_matches_type_name(const suppr::type_suppression& s,
bool
suppression_matches_type_location(const type_suppression& s,
- const location loc);
+ const location& loc);
bool
suppression_matches_type_location(const type_suppression& s,
diff --git a/src/abg-suppression.cc b/src/abg-suppression.cc
index b93a8ce..8d25f65 100644
--- a/src/abg-suppression.cc
+++ b/src/abg-suppression.cc
@@ -912,7 +912,7 @@ suppression_matches_type_name(const suppr::type_suppression& s,
/// @return true iff the suppression @p s matches location @p loc.
bool
suppression_matches_type_location(const type_suppression& s,
- const location loc)
+ const location& loc)
{
if (loc)
{
--
2.7.4