[07/11] ir: Speed up enum comparison
Commit Message
From: Dodji Seketeli <dodji@redhat.com>
When two enums are naively equal, comparing then member-wise should be
fast. This patch does just that. This speeds up things a lot, in the
context of self-comparison and type canonicalization (from DWARF) when
there are huge enums in the binary.
* src/abg-ir.cc (equals): In the overload for enums, compare
enumerators naively for the case both enums are naively equal.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
---
src/abg-ir.cc | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
@@ -19997,7 +19997,34 @@ equals(const enum_type_decl& l, const enum_type_decl& r, change_kind* k)
ABG_RETURN_FALSE;
}
- // Now compare the enumerators. Note that the order of declaration
+ // Now compare the enumerators.
+
+ // First in a naive (but potentially fast) way in case both enums
+ // are equal in a naive manner.
+
+ if (def1->get_enumerators().size() == def2->get_enumerators().size())
+ {
+ bool equals = true;
+ for (auto e1 = def1->get_enumerators().begin(),
+ e2 = def2->get_enumerators().begin();
+ (e1 != def1->get_enumerators().end()
+ && e2 != def2->get_enumerators().end());
+ ++e1, ++e2)
+ {
+ if (*e1 != *e2)
+ {
+ equals = false;
+ break;
+ }
+ }
+ if (equals)
+ ABG_RETURN(result);
+ }
+
+ // If the two enums where not naively equals, let's try a more
+ // clever (and slow) way.
+
+ // Note that the order of declaration
// of enumerators should not matter in the comparison.
//
// Also if an enumerator value is redundant, that shouldn't impact