Commit 8207cf0e authored by Mark Olesen's avatar Mark Olesen
Browse files

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
parent 8d63073b
......@@ -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;
}
}
}
......
Supports Markdown
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