Commit b770ddf3 authored by Mark Olesen's avatar Mark Olesen
Browse files

DynamicList - consistent setSize() behaviour

  - expansion of a list beyond the currently addressed list size
    changes both the allocated size and the addressed list size

  - contracting list below the currently addressed list size
    changes the addressed list size only.

  If someone really wishes to increase the underlying allocated list size
  without touching the addressed list size:

      prevSize = myList.size();
      myList.setSize(largerSize);
      myList.setSize(prevSize);

  or introduce an equivalent allocSize(const label) method if this is needed
parent b92ed1ec
......@@ -117,16 +117,18 @@ public:
// Edit
//- Alter the list size.
// When the new size is smaller than the addressed list size,
// the addressed list size is reduced and the allocated size
// does not change.
// Otherwise the allocated size is adjusted, but the
// addressed list size does not change.
// When the new size is greater than the addressed list size, both
// allocated and addressed list sizes are adjusted to the new size.
// Otherwise the addressed list size is just reduced and
// the allocated size does not change.
inline void setSize(const label);
//- Alter the list size and assign a value for new elements.
// If the new size is larger than the addressed list size,
// both allocated and addressed list sizes are adjusted.
// When the new size is greater than the addressed list size, both
// allocated and addressed list sizes are adjusted to the new size
// and a const value is assigned for the newly addressed elements.
// Otherwise the addressed list size is just reduced and
// the allocated size does not change.
inline void setSize(const label, const T&);
//- Clear the list, i.e. set the size to zero.
......
......@@ -86,11 +86,9 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
}
else
{
// adjust allocated size, leave addressed size untouched
label nextFree = List<T>::size();
// adjust allocated and addressed sizes
allocSize_ = s;
List<T>::setSize(allocSize_);
List<T>::size(nextFree);
}
}
......@@ -104,14 +102,13 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
{
if (s <= List<T>::size())
{
// shrink addressed size, leave allocated size untouched
// adjust addressed size, leave allocated size untouched
List<T>::size(s);
}
else
{
// increase allocated size and fill previously unused elements
// with constant value.
// The addressed size now matches the allocated size
// adjust allocated and addressed sizes
// fill previously unused elements with constant value
allocSize_ = s;
List<T>::setSize(allocSize_, 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