* commit '90ac50ee433d7ecb1a89da242d0d99b882169d17': Add BufferWithExtendableBuffer::extend()
This commit is contained in:
commit
917f8002c0
2 changed files with 12 additions and 6 deletions
|
@ -49,6 +49,10 @@ void BufferWithExtendableBuffer::readCodePointsAndAdvancePosition(const int maxC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BufferWithExtendableBuffer::extend(const int size) {
|
||||||
|
return checkAndPrepareWriting(getTailPosition(), size);
|
||||||
|
}
|
||||||
|
|
||||||
bool BufferWithExtendableBuffer::writeUint(const uint32_t data, const int size, const int pos) {
|
bool BufferWithExtendableBuffer::writeUint(const uint32_t data, const int size, const int pos) {
|
||||||
int writingPos = pos;
|
int writingPos = pos;
|
||||||
return writeUintAndAdvancePosition(data, size, &writingPos);
|
return writeUintAndAdvancePosition(data, size, &writingPos);
|
||||||
|
@ -96,13 +100,13 @@ bool BufferWithExtendableBuffer::writeCodePointsAndAdvancePosition(const int *co
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BufferWithExtendableBuffer::extendBuffer() {
|
bool BufferWithExtendableBuffer::extendBuffer(const size_t size) {
|
||||||
const size_t sizeAfterExtending =
|
const size_t extendSize = std::max(EXTEND_ADDITIONAL_BUFFER_SIZE_STEP, size);
|
||||||
mAdditionalBuffer.size() + EXTEND_ADDITIONAL_BUFFER_SIZE_STEP;
|
const size_t sizeAfterExtending = mAdditionalBuffer.size() + extendSize;
|
||||||
if (sizeAfterExtending > mMaxAdditionalBufferSize) {
|
if (sizeAfterExtending > mMaxAdditionalBufferSize) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mAdditionalBuffer.resize(mAdditionalBuffer.size() + EXTEND_ADDITIONAL_BUFFER_SIZE_STEP);
|
mAdditionalBuffer.resize(sizeAfterExtending);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +137,7 @@ bool BufferWithExtendableBuffer::checkAndPrepareWriting(const int pos, const int
|
||||||
}
|
}
|
||||||
const size_t extendSize = totalRequiredSize -
|
const size_t extendSize = totalRequiredSize -
|
||||||
std::min(mAdditionalBuffer.size() + mOriginalBufferSize, totalRequiredSize);
|
std::min(mAdditionalBuffer.size() + mOriginalBufferSize, totalRequiredSize);
|
||||||
if (extendSize > 0 && !extendBuffer()) {
|
if (extendSize > 0 && !extendBuffer(extendSize)) {
|
||||||
// Failed to extend the buffer.
|
// Failed to extend the buffer.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,8 @@ class BufferWithExtendableBuffer {
|
||||||
* NEAR_BUFFER_LIMIT_THRESHOLD_PERCENTILE) / 100);
|
* NEAR_BUFFER_LIMIT_THRESHOLD_PERCENTILE) / 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool extend(const int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For writing.
|
* For writing.
|
||||||
*
|
*
|
||||||
|
@ -115,7 +117,7 @@ class BufferWithExtendableBuffer {
|
||||||
const size_t mMaxAdditionalBufferSize;
|
const size_t mMaxAdditionalBufferSize;
|
||||||
|
|
||||||
// Return if the buffer is successfully extended or not.
|
// Return if the buffer is successfully extended or not.
|
||||||
bool extendBuffer();
|
bool extendBuffer(const size_t size);
|
||||||
|
|
||||||
// Returns if it is possible to write size-bytes from pos. When pos is at the tail position of
|
// Returns if it is possible to write size-bytes from pos. When pos is at the tail position of
|
||||||
// the additional buffer, try extending the buffer.
|
// the additional buffer, try extending the buffer.
|
||||||
|
|
Loading…
Reference in a new issue