Skip to content

Commit 935b81b

Browse files
committed
addressing comments regarding the FastSmallVector::expandSize
it is renamed to a more general resize and the function is revised accordingly.
1 parent 464190a commit 935b81b

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

opm/material/common/FastSmallVector.hpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,23 @@ class FastSmallVector
198198
}
199199
}
200200

201-
void expandSize(size_t numElem)
201+
void resize(size_t numElem)
202202
{
203-
assert(numElem >= size_);
204-
if (size_ <= N) {
203+
if (numElem == size_) return; // nothing to do
204+
205+
if (dataPtr_ == smallBuf_.data()) {
205206
if (numElem > N) {
206-
data_.resize(numElem, 0);
207-
data_.assign(smallBuf_.begin(), smallBuf_.begin() + size_);
207+
data_.resize(numElem);
208+
std::copy(smallBuf_.begin(), smallBuf_.begin() + size_, data_.begin());
208209
dataPtr_ = data_.data();
210+
} else if (numElem < size_) {
211+
// when shrinking, remove the values after numElem so that the space
212+
// is ready to use in the potentional future resize
213+
std::fill(smallBuf_.begin() + numElem, smallBuf_.begin() + size_, ValueType{});
209214
}
210215
} else {
211-
data_.resize(numElem, 0);
216+
// when shriking to numElem < N, we do not switch back to use smallBuf_
217+
data_.resize(numElem);
212218
}
213219
size_ = numElem;
214220
}

opm/material/densead/DynamicEvaluation.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ class Evaluation<ValueT, DynamicSize, staticSize>
691691
void appendDerivativesToConstant(size_t numDer) {
692692
assert(size() == 0); // we only append derivatives to a constant
693693
if (numDer > 0) {
694-
data_.expandSize(1 + numDer);
694+
data_.resize(1 + numDer);
695695
}
696696
}
697697
};

0 commit comments

Comments
 (0)