diff mbox series

[v2,3/5] Eliminate redundant conditional operators.

Message ID 20200501155148.98623-4-gprocida@google.com
State Committed
Headers show
Series Clean-ups. | expand

Commit Message

Giuliano Procida May 1, 2020, 3:51 p.m. UTC
Code of the form

  bool x = expression ? true : false;

can be written more concisely as

  bool x = expression;

This patch does this. There are no occurences of "? false : true".

	* src/abg-corpus.cc (corpus::priv::build_unreferenced_symbols_tables):
	Eliminate redundant conditional operator.
	* src/abg-dwarf-reader.cc (build_reference_type): Ditto.
	* src/abg-reader.cc (read_static): Ditto.
	(read_is_artificial): Ditto. (build_function_parameter):
	Ditto. (build_function_decl): Ditto.
	(build_qualified_type_decl): Ditto.
	(build_reference_type_def): Ditto.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
---
 src/abg-corpus.cc       |  4 ++--
 src/abg-dwarf-reader.cc |  2 +-
 src/abg-reader.cc       | 16 ++++++++--------
 3 files changed, 11 insertions(+), 11 deletions(-)

Comments

Dodji Seketeli May 11, 2020, 12:25 p.m. UTC | #1
Giuliano Procida <gprocida@google.com> a ?crit:

> Code of the form
>
>   bool x = expression ? true : false;
>
> can be written more concisely as
>
>   bool x = expression;
>
> This patch does this. There are no occurences of "? false : true".
>
> 	* src/abg-corpus.cc (corpus::priv::build_unreferenced_symbols_tables):
> 	Eliminate redundant conditional operator.
> 	* src/abg-dwarf-reader.cc (build_reference_type): Ditto.
> 	* src/abg-reader.cc (read_static): Ditto.
> 	(read_is_artificial): Ditto. (build_function_parameter):
> 	Ditto. (build_function_decl): Ditto.
> 	(build_qualified_type_decl): Ditto.
> 	(build_reference_type_def): Ditto.

Applied to master, thanks!

Cheers,
diff mbox series

Patch

diff --git a/src/abg-corpus.cc b/src/abg-corpus.cc
index ebdf8f29..147737d2 100644
--- a/src/abg-corpus.cc
+++ b/src/abg-corpus.cc
@@ -377,7 +377,7 @@  corpus::priv::build_unreferenced_symbols_tables()
 	    string sym_id = (*s)->get_id_string();
 	    if (refed_funs.find(sym_id) == refed_funs.end())
 	      {
-		bool keep = sym_id_fns_to_keep.empty() ? true : false;
+		bool keep = sym_id_fns_to_keep.empty();
 		for (vector<string>::const_iterator i =
 		       sym_id_fns_to_keep.begin();
 		     i != sym_id_fns_to_keep.end();
@@ -416,7 +416,7 @@  corpus::priv::build_unreferenced_symbols_tables()
 	    string sym_id = (*s)->get_id_string();
 	    if (refed_vars.find(sym_id) == refed_vars.end())
 	      {
-		bool keep = sym_id_vars_to_keep.empty() ? true : false;
+		bool keep = sym_id_vars_to_keep.empty();
 		for (vector<string>::const_iterator i =
 		       sym_id_vars_to_keep.begin();
 		     i != sym_id_vars_to_keep.end();
diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index 8cbf0046..63837554 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -14779,7 +14779,7 @@  build_reference_type(read_context&	ctxt,
   // of the current translation unit.
   ABG_ASSERT((size_t) ctxt.cur_transl_unit()->get_address_size() == size);
 
-  bool is_lvalue = (tag == DW_TAG_reference_type) ? true : false;
+  bool is_lvalue = tag == DW_TAG_reference_type;
 
   result.reset(new reference_type_def(utype, is_lvalue, size,
 				      /*alignment=*/0,
diff --git a/src/abg-reader.cc b/src/abg-reader.cc
index 2e31f320..47ac6229 100644
--- a/src/abg-reader.cc
+++ b/src/abg-reader.cc
@@ -2442,7 +2442,7 @@  read_static(xmlNodePtr node, bool& is_static)
   if (xml_char_sptr s = XML_NODE_GET_ATTRIBUTE(node, "static"))
     {
       string b = CHAR_STR(s);
-      is_static = (b == "yes") ? true : false;
+      is_static = b == "yes";
       return true;
     }
   return false;
@@ -2567,7 +2567,7 @@  read_is_artificial(xmlNodePtr node, bool& is_artificial)
   if (xml_char_sptr s = XML_NODE_GET_ATTRIBUTE(node, "is-artificial"))
     {
       string is_artificial_str = CHAR_STR(s) ? CHAR_STR(s) : "";
-      is_artificial = (is_artificial_str == "yes") ? true : false;
+      is_artificial = is_artificial_str == "yes";
       return true;
     }
   return false;
@@ -3071,7 +3071,7 @@  build_function_parameter(read_context& ctxt, const xmlNodePtr node)
       xml::build_sptr(xmlGetProp(node, BAD_CAST("is-variadic"))))
     {
       is_variadic_str = CHAR_STR(s) ? CHAR_STR(s) : "";
-      is_variadic = (is_variadic_str == "yes") ? true : false;
+      is_variadic = is_variadic_str == "yes";
     }
 
   bool is_artificial = false;
@@ -3146,7 +3146,7 @@  build_function_decl(read_context&	ctxt,
   string inline_prop;
   if (xml_char_sptr s = XML_NODE_GET_ATTRIBUTE(node, "declared-inline"))
     inline_prop = CHAR_STR(s);
-  bool declared_inline = inline_prop == "yes" ? true : false;
+  bool declared_inline = inline_prop == "yes";
 
   decl_base::visibility vis = decl_base::VISIBILITY_NONE;
   read_visibility(node, vis);
@@ -3583,17 +3583,17 @@  build_qualified_type_decl(read_context&	ctxt,
   string const_str;
   if (xml_char_sptr s = XML_NODE_GET_ATTRIBUTE(node, "const"))
     const_str = CHAR_STR(s);
-  bool const_cv = const_str == "yes" ? true : false;
+  bool const_cv = const_str == "yes";
 
   string volatile_str;
   if (xml_char_sptr s = XML_NODE_GET_ATTRIBUTE(node, "volatile"))
     volatile_str = CHAR_STR(s);
-  bool volatile_cv = volatile_str == "yes" ? true : false;
+  bool volatile_cv = volatile_str == "yes";
 
   string restrict_str;
   if (xml_char_sptr s = XML_NODE_GET_ATTRIBUTE(node, "restrict"))
     restrict_str = CHAR_STR(s);
-  bool restrict_cv = restrict_str == "yes" ? true : false;
+  bool restrict_cv = restrict_str == "yes";
 
   qualified_type_def::CV cv = qualified_type_def::CV_NONE;
   if (const_cv)
@@ -3743,7 +3743,7 @@  build_reference_type_def(read_context&		ctxt,
   string kind;
   if (xml_char_sptr s = XML_NODE_GET_ATTRIBUTE(node, "kind"))
     kind = CHAR_STR(s); // this should be either "lvalue" or "rvalue".
-  bool is_lvalue = kind == "lvalue" ? true : false;
+  bool is_lvalue = kind == "lvalue";
 
   string type_id;
   if (xml_char_sptr s = XML_NODE_GET_ATTRIBUTE(node, "type-id"))