From 2c6b13687684279208eaecd136ec70db1f35aafc Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 13 Oct 2008 11:54:19 +0200 Subject: [PATCH] DynamicList changes - setSize(const label) * When the new size is greater than the addressed list size, the allocated list sizes is adjusted and the addressed size does not change. * Otherwise the addressed list size is just reduced and the allocated size does not change. inline void setSize(const label); - setSize(const label, const T&) Disabled, since the usefulness and semantics are not quite clear - operator=(const T&) should not affect the allocated size (BUGFIX) --- .../Lists/DynamicList/DynamicList.H | 24 +++++++------- .../Lists/DynamicList/DynamicListI.H | 31 +++---------------- 2 files changed, 16 insertions(+), 39 deletions(-) diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H index db092cebc1..3891ad0ea8 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H @@ -84,6 +84,11 @@ class DynamicList //- Allocated size for underlying List. label allocSize_; + // Private Member Functions + + // Disabled, since the usefulness and semantics are not quite clear + void setSize(const label, const T&); + public: // Related types @@ -117,20 +122,13 @@ public: // Edit //- Alter the list size. - // 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. + // When the new size is greater than the addressed list size, the + // allocated list sizes is adjusted and the + // addressed size does not change. + // 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. - // 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. // Allocated size does not change inline void clear(); @@ -164,7 +162,7 @@ public: // resizing the list if necessary inline T& operator()(const label); - //- Assignment of all entries to the given value + //- Assignment of all addressed entries to the given value inline void operator=(const T&); //- Assignment from List. Also handles assignment from DynamicList. diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index 145c90ae9c..434dfcb468 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -79,39 +79,19 @@ inline void Foam::DynamicList::setSize const label s ) { - if (s <= List::size()) + label nextFree = List::size(); + if (s <= nextFree) { // adjust addressed size, leave allocated size untouched - List::size(s); + nextFree = s; } else { - // adjust allocated and addressed sizes + // adjust allocated size, leave addressed size untouched allocSize_ = s; List::setSize(allocSize_); } -} - - -template -inline void Foam::DynamicList::setSize -( - const label s, - const T& t -) -{ - if (s <= List::size()) - { - // adjust addressed size, leave allocated size untouched - List::size(s); - } - else - { - // adjust allocated and addressed sizes - // fill previously unused elements with constant value - allocSize_ = s; - List::setSize(allocSize_, t); - } + List::size(nextFree); } @@ -254,7 +234,6 @@ inline void Foam::DynamicList::operator= ) { List::operator=(t); - allocSize_ = List::size(); }