From 8207cf0e476e7213b144e206979b8c7e7e21976d Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> Date: Fri, 10 Oct 2008 13:30:54 +0200 Subject: [PATCH] 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 --- .../Lists/DynamicList/DynamicListI.H | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index 8ab5f7cef4c..b186893484b 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -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; + } + } } -- GitLab