Skip to content
Snippets Groups Projects
Commit 02b946cf authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: add short-circuit (break) on various List operator==()

- performance improvement. Noticed while examining issue #458
parent 9269c517
Branches
Tags
1 merge request!121Merge develop into master for v1706 release
......@@ -57,19 +57,19 @@ bool Foam::UILList<LListBase, T>::operator==
const UILList<LListBase, T>& rhs
) const
{
if (this->size() != rhs.size())
bool equal = (this->size() == rhs.size());
if (!equal)
{
return false;
}
bool equal = true;
const_iterator iter1 = this->begin();
const_iterator iter2 = rhs.begin();
for (; iter1 != this->end(); ++iter1, ++iter2)
{
equal = equal && iter1() == iter2();
equal = (iter1() == iter2());
if (!equal) break;
}
return equal;
......
......@@ -53,7 +53,8 @@ bool Foam::FixedList<T, Size>::operator==(const FixedList<T, Size>& a) const
List_CONST_ACCESS(T, (a), ap);
List_FOR_ALL((*this), i)
equal = equal && (List_ELEM((*this), vp, i) == List_ELEM((a), ap, i));
equal = (List_ELEM((*this), vp, i) == List_ELEM((a), ap, i));
if (!equal) break;
List_END_FOR_ALL
return equal;
......
......@@ -22,8 +22,7 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
List\<T\> is a 1D vector of objects of type T, where the size of the
vector is known and used for subscript bounds checking, etc.
Macros for accessing List elements
\*---------------------------------------------------------------------------*/
......@@ -37,8 +36,8 @@ Description
// Element access looping using [] for vector machines
#define List_FOR_ALL(f, i) \
const label _n##i = (f).size();\
for (label i=0; i<_n##i; i++) \
const label _n##i = (f).size(); \
for (label i=0; i<_n##i; ++i) \
{
#define List_END_FOR_ALL }
......@@ -60,7 +59,7 @@ Description
// Pointer looping for scalar machines
#define List_FOR_ALL(f, i) \
label i = (f).size(); \
label i = (f).size(); \
while (i--) \
{ \
......
......@@ -151,18 +151,18 @@ void Foam::shuffle(UList<T>& a)
template<class T>
bool Foam::UList<T>::operator==(const UList<T>& a) const
{
if (this->size_ != a.size_)
bool equal = (this->size_ == a.size_);
if (!equal)
{
return false;
}
bool equal = true;
List_CONST_ACCESS(T, (*this), vp);
List_CONST_ACCESS(T, (a), ap);
List_FOR_ALL((*this), i)
equal = equal && (List_ELEM((*this), vp, i) == List_ELEM((a), ap, i));
equal = (List_ELEM((*this), vp, i) == List_ELEM((a), ap, i));
if (!equal) break;
List_END_FOR_ALL
return equal;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment