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