diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H index 684d393745..e913209b2f 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H @@ -26,7 +26,7 @@ Class Foam::DynamicList Description - A 1D vector of objects of type \ which resizes itself as necessary to + A 1D vector of objects of type \ that resizes itself as necessary to accept the new objects. Internal storage is a compact array and the list can be shrunk to compact @@ -149,7 +149,7 @@ public: //- Append an element at the end of the list inline void append(const T& e); - //- Return and remove the top element + //- Remove and return the top element inline T remove(); //- Return non-const access to an element, @@ -159,15 +159,9 @@ public: //- Assignment of all entries to the given value inline void operator=(const T&); - //- Assignment from List + //- Assignment from List. Also handles assignment from DynamicList. inline void operator=(const List&); - //- Assignment from DynamicList - inline void operator= - ( - const DynamicList& - ); - // IOstream operators diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index d9a14a1111..eea08bc7a1 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -85,8 +85,10 @@ inline void Foam::DynamicList::setSize } else { + label nextFree = List::size(); allocSize_ = s; List::setSize(allocSize_); + List::size() = nextFree; } } @@ -104,8 +106,10 @@ inline void Foam::DynamicList::setSize } else { + label nextFree = List::size(); allocSize_ = s; List::setSize(allocSize_, t); + List::size() = nextFree; } } @@ -166,8 +170,7 @@ Foam::DynamicList::transfer ) { allocSize_ = l.allocSize(); - List::transfer(l); // take over storage - l.allocSize_ = 0; + List::transfer(l); // take over storage. Null l. } @@ -189,9 +192,9 @@ inline void Foam::DynamicList::append(const T& e) List::setSize(allocSize_); } - this->operator[](nextFree - 1) = e; - List::size() = nextFree; + + this->operator[](nextFree - 1) = e; } @@ -206,7 +209,13 @@ inline T Foam::DynamicList::remove() ) << "List is empty" << abort(FatalError); } - return List::operator[](--List::size()); + label nextFree = List::size()-1; + + const T& val = List::operator[](nextFree); + + List::size() = nextFree; + + return val; } @@ -260,15 +269,4 @@ inline void Foam::DynamicList::operator= } -template -inline void Foam::DynamicList::operator= -( - const DynamicList& l -) -{ - List::operator=(l); - allocSize_ = l.allocSize(); -} - - // ************************************************************************* //