[v2,2/4] crc_changed: eliminate copying of shared_ptr values

Message ID 20220316163055.4127796-3-gprocida@google.com
State New
Headers
Series add symbol namespace support, update symbol CRC support |

Commit Message

Giuliano Procida March 16, 2022, 4:30 p.m. UTC
  As pointed out in a review of similar code, it is possible to avoid
copying a couple of shared pointers in this function, by taking
references instead.

This commit also splits declarations to one per line and removes the
unnecessary parentheses around the return expression.

	* src/abg-comp-filter.cc (crc_changed): Take references to
	avoid std::shared_ptr copying. Split declarations into one per
	line. Remove unnecessary return expression parentheses.

Signed-off-by: Giuliano Procida <gprocida@google.com>
---
 src/abg-comp-filter.cc | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
  

Comments

Matthias Männich March 17, 2022, 11:01 a.m. UTC | #1
On Wed, Mar 16, 2022 at 04:30:53PM +0000, Giuliano Procida via Libabigail wrote:
>As pointed out in a review of similar code, it is possible to avoid
>copying a couple of shared pointers in this function, by taking
>references instead.
>
>This commit also splits declarations to one per line and removes the
>unnecessary parentheses around the return expression.
>
>	* src/abg-comp-filter.cc (crc_changed): Take references to
>	avoid std::shared_ptr copying. Split declarations into one per
>	line. Remove unnecessary return expression parentheses.
>
>Signed-off-by: Giuliano Procida <gprocida@google.com>

Reviewed-by: Matthias Maennich <maennich@google.com>

Cheers,
Matthias

>---
> src/abg-comp-filter.cc | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
>diff --git a/src/abg-comp-filter.cc b/src/abg-comp-filter.cc
>index 56251274..f90fdc78 100644
>--- a/src/abg-comp-filter.cc
>+++ b/src/abg-comp-filter.cc
>@@ -230,11 +230,13 @@ static bool
> crc_changed(const function_or_var_decl_sptr& f,
> 	    const function_or_var_decl_sptr& s)
> {
>-  const auto symbol_f  = f->get_symbol(), symbol_s = s->get_symbol();
>+  const auto& symbol_f = f->get_symbol();
>+  const auto& symbol_s = s->get_symbol();
>   if (!symbol_f || !symbol_s)
>     return false;
>-  const auto crc_f = symbol_f->get_crc(), crc_s = symbol_s->get_crc();
>-  return (crc_f != 0 && crc_s != 0 && crc_f != crc_s);
>+  const auto crc_f = symbol_f->get_crc();
>+  const auto crc_s = symbol_s->get_crc();
>+  return crc_f != 0 && crc_s != 0 && crc_f != crc_s;
> }
>
> /// Test if the current diff tree node carries a CRC change in either a
>-- 
>2.35.1.894.gb6a874cedc-goog
>
  

Patch

diff --git a/src/abg-comp-filter.cc b/src/abg-comp-filter.cc
index 56251274..f90fdc78 100644
--- a/src/abg-comp-filter.cc
+++ b/src/abg-comp-filter.cc
@@ -230,11 +230,13 @@  static bool
 crc_changed(const function_or_var_decl_sptr& f,
 	    const function_or_var_decl_sptr& s)
 {
-  const auto symbol_f  = f->get_symbol(), symbol_s = s->get_symbol();
+  const auto& symbol_f = f->get_symbol();
+  const auto& symbol_s = s->get_symbol();
   if (!symbol_f || !symbol_s)
     return false;
-  const auto crc_f = symbol_f->get_crc(), crc_s = symbol_s->get_crc();
-  return (crc_f != 0 && crc_s != 0 && crc_f != crc_s);
+  const auto crc_f = symbol_f->get_crc();
+  const auto crc_s = symbol_s->get_crc();
+  return crc_f != 0 && crc_s != 0 && crc_f != crc_s;
 }
 
 /// Test if the current diff tree node carries a CRC change in either a