From ca45cf1614ad8ea40d17172e2cfae3739e59bddf Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Sat, 4 Jun 2016 17:45:11 +0100 Subject: [PATCH] DynamicList: minor cleanup --- .../Lists/DynamicList/DynamicListI.H | 65 +++++-------------- 1 file changed, 17 insertions(+), 48 deletions(-) diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index fdd4ec571a..97a0b72483 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -28,11 +28,8 @@ License template inline Foam::DynamicList::DynamicList() : - List(0), capacity_(0) -{ - List::size(0); -} +{} template @@ -144,28 +141,14 @@ inline void Foam::DynamicList::reserve const label nElem ) { - // Allocate more capacity? + // Allocate more capacity if necessary if (nElem > capacity_) { - // TODO: convince the compiler that division by zero does not occur - // if (SizeInc && (!SizeMult || !SizeDiv)) - // { - // // resize with SizeInc as the granularity - // capacity_ = nElem; - // unsigned pad = SizeInc - (capacity_ % SizeInc); - // if (pad != SizeInc) - // { - // capacity_ += pad; - // } - // } - // else - { - capacity_ = max - ( - nElem, - label(SizeInc + capacity_ * SizeMult / SizeDiv) - ); - } + capacity_ = max + ( + nElem, + label(SizeInc + capacity_ * SizeMult / SizeDiv) + ); // Adjust allocated size, leave addressed size untouched label nextFree = List::size(); @@ -181,28 +164,14 @@ inline void Foam::DynamicList::setSize const label nElem ) { - // Allocate more capacity? + // Allocate more capacity if necessary if (nElem > capacity_) { - // TODO: convince the compiler that division by zero does not occur - // if (SizeInc && (!SizeMult || !SizeDiv)) - // { - // // resize with SizeInc as the granularity - // capacity_ = nElem; - // unsigned pad = SizeInc - (capacity_ % SizeInc); - // if (pad != SizeInc) - // { - // capacity_ += pad; - // } - // } - // else - { - capacity_ = max - ( - nElem, - label(SizeInc + capacity_ * SizeMult / SizeDiv) - ); - } + capacity_ = max + ( + nElem, + label(SizeInc + capacity_ * SizeMult / SizeDiv) + ); List::setSize(capacity_); } @@ -289,8 +258,9 @@ template inline void Foam::DynamicList::transfer(List& lst) { + // Take over storage, clear addressing for lst. capacity_ = lst.size(); - List::transfer(lst); // Take over storage, clear addressing for lst. + List::transfer(lst); } @@ -304,7 +274,6 @@ Foam::DynamicList::transfer // Take over storage as-is (without shrink), clear addressing for lst. capacity_ = lst.capacity_; lst.capacity_ = 0; - List::transfer(static_cast&>(lst)); } @@ -342,7 +311,7 @@ Foam::DynamicList::append if (this == &lst) { FatalErrorInFunction - << "attempted appending to self" << abort(FatalError); + << "Attempted appending to self" << abort(FatalError); } label nextFree = List::size(); @@ -429,7 +398,7 @@ inline void Foam::DynamicList::operator= if (this == &lst) { FatalErrorInFunction - << "attempted assignment to self" << abort(FatalError); + << "Attempted assignment to self" << abort(FatalError); } if (capacity_ >= lst.size())