Shared : Larger buffer increments
This change will reduce the quantity of small requests to increment the character assembly buffer when parsing JSON. Change-Id: I0998f6fb403bf6dc4736585bb69a103f3976a448 Reviewed-on: https://review.haiku-os.org/c/haiku/+/7115 Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org> Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
This commit is contained in:
parent
a143f249c2
commit
916c6d9492
@ -136,12 +136,23 @@ private:
|
||||
status_t _EnsureAssemblyBufferAllocatedSize(size_t minimumSize)
|
||||
{
|
||||
if (fAssemblyBufferAllocatedSize < minimumSize) {
|
||||
fAssemblyBuffer = (char*) realloc(fAssemblyBuffer, minimumSize);
|
||||
size_t requestedSize = minimumSize;
|
||||
|
||||
// if the requested quantity of memory is less than the retained buffer size then
|
||||
// it makes sense to request a wee bit more in order to reduce the number of small
|
||||
// requests to increment the buffer over time.
|
||||
|
||||
if (requestedSize < kRetainedAssemblyBufferSize - kAssemblyBufferSizeIncrement) {
|
||||
requestedSize = ((requestedSize / kAssemblyBufferSizeIncrement) + 1)
|
||||
* kAssemblyBufferSizeIncrement;
|
||||
}
|
||||
|
||||
fAssemblyBuffer = (char*) realloc(fAssemblyBuffer, requestedSize);
|
||||
if (fAssemblyBuffer == NULL) {
|
||||
fAssemblyBufferAllocatedSize = 0;
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
fAssemblyBufferAllocatedSize = minimumSize;
|
||||
fAssemblyBufferAllocatedSize = requestedSize;
|
||||
}
|
||||
return B_OK;
|
||||
}
|
||||
@ -230,6 +241,8 @@ public:
|
||||
|
||||
void PushbackChar(char c)
|
||||
{
|
||||
if (fHasPushbackChar)
|
||||
debugger("illegal state - more than one character pushed back");
|
||||
fPushbackChar = c;
|
||||
fHasPushbackChar = true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user