STYLE: compare Dynamic{Field,List} by casting address to common class

- previously used cdata() comparison but that tends to obscure what is
  going on
This commit is contained in:
Mark Olesen
2022-05-17 11:17:14 +02:00
parent 87f3866f20
commit f1098673c0
2 changed files with 42 additions and 21 deletions

View File

@ -445,8 +445,11 @@ inline void Foam::DynamicList<T, SizeMin>::swap
DynamicList<T, AnySizeMin>& other
)
{
// Cannot compare 'this' for different types, so use cdata()
if (this->cdata() == other.cdata())
if
(
static_cast<const List<T>*>(this)
== static_cast<const List<T>*>(&other)
)
{
return; // Self-swap is a no-op
}
@ -477,8 +480,11 @@ Foam::DynamicList<T, SizeMin>::transfer
DynamicList<T, AnySizeMin>& list
)
{
// Cannot compare 'this' for different types, so use cdata()
if (this->cdata() == list.cdata())
if
(
static_cast<const List<T>*>(this)
== static_cast<const List<T>*>(&list)
)
{
return; // Self-assignment is a no-op
}
@ -808,8 +814,11 @@ inline void Foam::DynamicList<T, SizeMin>::operator=
const DynamicList<T, AnySizeMin>& list
)
{
// Cannot compare 'this' for different types, so use cdata()
if (this->cdata() == list.cdata())
if
(
static_cast<const List<T>*>(this)
== static_cast<const List<T>*>(&list)
)
{
return; // Self-assignment is a no-op
}
@ -873,8 +882,11 @@ inline void Foam::DynamicList<T, SizeMin>::operator=
DynamicList<T, AnySizeMin>&& list
)
{
// Cannot compare 'this' for different types, so use cdata()
if (this->cdata() == list.cdata())
if
(
static_cast<const List<T>*>(this)
== static_cast<const List<T>*>(&list)
)
{
return; // Self-assignment is a no-op
}

View File

@ -486,8 +486,11 @@ inline void Foam::DynamicField<T, SizeMin>::swap
DynamicField<T, AnySizeMin>& other
)
{
// Cannot compare 'this' for different types, so use cdata()
if (this->cdata() == other.cdata())
if
(
static_cast<const List<T>*>(this)
== static_cast<const List<T>*>(&other)
)
{
return; // Self-swap is a no-op
}
@ -507,11 +510,11 @@ inline void Foam::DynamicField<T, SizeMin>::swap
DynamicList<T, AnySizeMin>& other
)
{
auto& self = (*this);
// ... not yet needed:
// Cannot compare 'this' for different types, so use cdata()
if (self.cdata() == other.cdata())
if
(
static_cast<const List<T>*>(this)
== static_cast<const List<T>*>(&other)
)
{
return; // Self-swap is a no-op
}
@ -520,10 +523,10 @@ inline void Foam::DynamicField<T, SizeMin>::swap
UList<T>::swap(other);
// Swap capacity
const label oldCap = self.capacity();
const label oldCap = this->capacity();
const label newCap = other.capacity();
self.setCapacity_unsafe(newCap);
this->setCapacity_unsafe(newCap);
other.setCapacity_unsafe(oldCap);
}
@ -544,8 +547,11 @@ inline void Foam::DynamicField<T, SizeMin>::transfer
DynamicList<T, AnySizeMin>& list
)
{
// Cannot compare 'this' for different types, so use cdata()
if (this->cdata() == list.cdata())
if
(
static_cast<const List<T>*>(this)
== static_cast<const List<T>*>(&list)
)
{
return; // Self-assignment is a no-op
}
@ -566,8 +572,11 @@ inline void Foam::DynamicField<T, SizeMin>::transfer
DynamicField<T, AnySizeMin>& list
)
{
// Cannot compare 'this' for different types, so use cdata()
if (this->cdata() == list.cdata())
if
(
static_cast<const List<T>*>(this)
== static_cast<const List<T>*>(&list)
)
{
return; // Self-assignment is a no-op
}