]> sourceware.org Git - libabigail.git/commitdiff
Speedup some diff::has_changes() implementations
authorDodji Seketeli <dodji@redhat.com>
Sat, 7 Feb 2015 09:20:31 +0000 (10:20 +0100)
committerDodji Seketeli <dodji@redhat.com>
Sat, 7 Feb 2015 10:00:05 +0000 (11:00 +0100)
Some implementations of diff::has_changes() are high on performance
profiles. This patch make them faster by trying to detect as quickly
as possible cases where the diff node actually has changes.  The
longest past is to detect when the diff node does *not* have changes.
We'll deal the latter case later.

* src/abg-comparison.cc ({distinct_diff, var_diff,
class_diff}::has_changes): Use the hash value of the diff subjects
to detect quickly if they differ.  If they don't, then go the slow
path of comparing the types.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
src/abg-comparison.cc

index c806c5f37ba01675962ec959bdbf127a4d2c2070..67862b02de20e83a19b04da5df5321b7adf6c912 100644 (file)
@@ -3746,6 +3746,14 @@ distinct_diff::entities_are_of_distinct_kinds(decl_base_sptr first,
 bool
 distinct_diff::has_changes() const
 {
+  if (!!first().get() != !!second().get())
+    return true;
+  else if (first().get() == second().get())
+    return false;
+  else if (first()->get_hash() && second()->get_hash()
+          && (first()->get_hash() != second()->get_hash()))
+    return true;
+
   if (first() == second()
       || (first() && second()
          && *first() == *second()))
@@ -4750,7 +4758,19 @@ var_diff::type_diff() const
 /// @return true iff the diff node has a change.
 bool
 var_diff::has_changes() const
-{return *first_var() != *second_var();}
+{
+  if (!!first_var() != !!second_var())
+    return true;
+
+  if (first_var().get() == second_var().get())
+    return false;
+
+  if (first_var()->get_hash() && second_var()->get_hash()
+      && first_var()->get_hash() != second_var()->get_hash())
+    return true;
+
+  return *first_var() != *second_var();
+}
 
 /// @return true iff the current diff node carries local changes.
 bool
@@ -6922,7 +6942,17 @@ class_diff::get_pretty_representation() const
 /// @return true iff the current diff node carries a change.
 bool
 class_diff::has_changes() const
-{return (*first_class_decl() != *second_class_decl());}
+{
+  if (!!first_class_decl() != !! second_class_decl())
+    return true;
+  if (first_class_decl().get() == second_class_decl().get())
+    return false;
+  if (first_class_decl()->get_hash() && second_class_decl()->get_hash()
+      && first_class_decl()->get_hash() != second_class_decl()->get_hash())
+    return true;
+
+  return (*first_class_decl() != *second_class_decl());
+}
 
 /// @return true iff the current diff node carries local changes.
 bool
This page took 0.051164 seconds and 5 git commands to generate.