From baef3a7470fefa701f468ba5939f621d208c2b82 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 25 Jul 2022 09:56:42 +1000 Subject: Use size_t for sizing SplitVector as compatible with vector.size() which avoids casts and warnings. --- src/SplitVector.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/SplitVector.h b/src/SplitVector.h index d233a50ed..adaa8eeb8 100644 --- a/src/SplitVector.h +++ b/src/SplitVector.h @@ -19,7 +19,7 @@ protected: ptrdiff_t lengthBody; ptrdiff_t part1Length; ptrdiff_t gapLength; /// invariant: gapLength == body.size() - lengthBody - ptrdiff_t growSize; + size_t growSize; /// Move the gap to a particular position so that insertion and /// deletion at that point will not require much copying and @@ -54,7 +54,7 @@ protected: /// reallocating if more space needed. void RoomFor(ptrdiff_t insertionLength) { if (gapLength < insertionLength) { - while (growSize < static_cast(body.size() / 6)) + while (growSize < body.size() / 6) growSize *= 2; ReAllocate(body.size() + insertionLength + growSize); } @@ -83,25 +83,22 @@ public: ~SplitVector() { } - ptrdiff_t GetGrowSize() const noexcept { + size_t GetGrowSize() const noexcept { return growSize; } - void SetGrowSize(ptrdiff_t growSize_) noexcept { + void SetGrowSize(size_t growSize_) noexcept { growSize = growSize_; } /// Reallocate the storage for the buffer to be newSize and /// copy existing contents to the new buffer. /// Must not be used to decrease the size of the buffer. - void ReAllocate(ptrdiff_t newSize) { - if (newSize < 0) - throw std::runtime_error("SplitVector::ReAllocate: negative size."); - - if (newSize > static_cast(body.size())) { + void ReAllocate(size_t newSize) { + if (newSize > body.size()) { // Move the gap to the end GapTo(lengthBody); - gapLength += newSize - static_cast(body.size()); + gapLength += newSize - body.size(); // RoomFor implements a growth strategy but so does vector::resize so // ensure vector::resize allocates exactly the amount wanted by // calling reserve first. -- cgit v1.2.3