Commit ca45cf16 authored by Henry Weller's avatar Henry Weller
Browse files

DynamicList: minor cleanup

parent 91e84b90
......@@ -28,11 +28,8 @@ License
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList()
:
List<T>(0),
capacity_(0)
{
List<T>::size(0);
}
{}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
......@@ -144,28 +141,14 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::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<T>::size();
......@@ -181,28 +164,14 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::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<T>::setSize(capacity_);
}
......@@ -289,8 +258,9 @@ template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer(List<T>& lst)
{
// Take over storage, clear addressing for lst.
capacity_ = lst.size();
List<T>::transfer(lst); // Take over storage, clear addressing for lst.
List<T>::transfer(lst);
}
......@@ -304,7 +274,6 @@ Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer
// Take over storage as-is (without shrink), clear addressing for lst.
capacity_ = lst.capacity_;
lst.capacity_ = 0;
List<T>::transfer(static_cast<List<T>&>(lst));
}
......@@ -342,7 +311,7 @@ Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append
if (this == &lst)
{
FatalErrorInFunction
<< "attempted appending to self" << abort(FatalError);
<< "Attempted appending to self" << abort(FatalError);
}
label nextFree = List<T>::size();
......@@ -429,7 +398,7 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
if (this == &lst)
{
FatalErrorInFunction
<< "attempted assignment to self" << abort(FatalError);
<< "Attempted assignment to self" << abort(FatalError);
}
if (capacity_ >= lst.size())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment