diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H index d6553dcfab..2738b414b0 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H @@ -182,9 +182,14 @@ public: //- Assignment of all addressed entries to the given value inline void operator=(const T&); - //- Assignment from List. Also handles assignment from DynamicList. - inline void operator=(const UList&); + //- Assignment from DynamicList + inline void operator= + ( + const DynamicList& + ); + //- Assignment from List. + inline void operator=(const UList&); // IOstream operators diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index f1e7d40dd6..c573a5df5e 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -334,13 +334,36 @@ inline void Foam::DynamicList::operator= ( const UList& lst ) +{ + if (capacity_ >= lst.size()) + { + // can copy w/o reallocating, match initial size to avoid reallocation + List::size(lst.size()); + List::operator=(lst); + } + else + { + // make everything available for the copy operation + List::size(capacity_); + + List::operator=(lst); + capacity_ = List::size(); + } +} + + +template +inline void Foam::DynamicList::operator= +( + const DynamicList& lst +) { if (this == &lst) { FatalErrorIn ( "DynamicList::operator=" - "(const UList&)" + "(const DynamicList&)" ) << "attempted assignment to self" << abort(FatalError); }