diff options
author | Neil <nyamatongwe@gmail.com> | 2022-07-25 09:56:42 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2022-07-25 09:56:42 +1000 |
commit | baef3a7470fefa701f468ba5939f621d208c2b82 (patch) | |
tree | d2b753144e1c328eb7467e29dc8ba6ecf3af3294 /src/SplitVector.h | |
parent | cd7fa187157d8127f699a16f2ac247348206a601 (diff) | |
download | scintilla-mirror-baef3a7470fefa701f468ba5939f621d208c2b82.tar.gz |
Use size_t for sizing SplitVector as compatible with vector.size() which avoids
casts and warnings.
Diffstat (limited to 'src/SplitVector.h')
-rw-r--r-- | src/SplitVector.h | 17 |
1 files changed, 7 insertions, 10 deletions
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<ptrdiff_t>(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<ptrdiff_t>(body.size())) { + void ReAllocate(size_t newSize) { + if (newSize > body.size()) { // Move the gap to the end GapTo(lengthBody); - gapLength += newSize - static_cast<ptrdiff_t>(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. |