mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
more consistent behaviour for DynamicList::setSize()
- in most places this can now be used instead of label& List<T>::size(), and should also be much safer
This commit is contained in:
@ -79,12 +79,14 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
|
||||
const label s
|
||||
)
|
||||
{
|
||||
if (s < List<T>::size())
|
||||
if (s <= List<T>::size())
|
||||
{
|
||||
// shrink addressable size, leave allocated size untouched
|
||||
List<T>::size(s);
|
||||
}
|
||||
else
|
||||
else if (s > allocSize_)
|
||||
{
|
||||
// increase allocated size, leave addressable size untouched
|
||||
label nextFree = List<T>::size();
|
||||
allocSize_ = s;
|
||||
List<T>::setSize(allocSize_);
|
||||
@ -100,17 +102,30 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
|
||||
const T& t
|
||||
)
|
||||
{
|
||||
if (s < List<T>::size())
|
||||
if (s <= List<T>::size())
|
||||
{
|
||||
// shrink addressable size, leave allocated size untouched
|
||||
List<T>::size(s);
|
||||
}
|
||||
else
|
||||
else if (s > allocSize_)
|
||||
{
|
||||
// increase allocated size, leave addressable size untouched
|
||||
// fill in newly allocated values with constant value
|
||||
label nextFree = List<T>::size();
|
||||
allocSize_ = s;
|
||||
List<T>::setSize(allocSize_, t);
|
||||
List<T>::size(nextFree);
|
||||
}
|
||||
else
|
||||
{
|
||||
// leave allocated and addressable sizes untouched
|
||||
// fill in new exposed values with constant value
|
||||
label nextFree = List<T>::size();
|
||||
while (nextFree < s)
|
||||
{
|
||||
this->operator[](nextFree++) = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user