From b56227ee2b6c8d32ccb700a82c901d7c71a25ba3 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 11 Apr 2017 09:34:51 +0200 Subject: [PATCH] ENH: simplify HashSet equality test - reduce the amount of checking. Equivalent logic to what HashTable has. --- src/OpenFOAM/containers/HashTables/HashSet/HashSet.C | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C index 75bea5ce59..0b1456f81d 100644 --- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C +++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C @@ -121,16 +121,12 @@ inline bool Foam::HashSet::operator[](const Key& key) const template bool Foam::HashSet::operator==(const HashSet& rhs) const { - // Are all lhs elements in rhs? - for (const_iterator iter = this->cbegin(); iter != this->cend(); ++iter) + // Sizes (number of keys) must match + if (this->size() != rhs.size()) { - if (!rhs.found(iter.key())) - { - return false; - } + return false; } - // Are all rhs elements in lhs? for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter) { if (!this->found(iter.key()))