Don't shuffle input buffer unless actually needed

This commit is contained in:
Pierre Ossman 2020-05-16 11:32:26 +02:00 committed by Lauri Kasanen
parent 25995e2490
commit a55f142c98

View File

@ -51,12 +51,14 @@ bool BufferedInStream::overrun(size_t needed, bool wait)
"requested size of %lu bytes exceeds maximum of %lu bytes",
(long unsigned)needed, (long unsigned)bufSize);
if (end - ptr != 0)
// Do we need to shuffle things around?
if ((bufSize - (ptr - start)) < needed) {
memmove(start, ptr, end - ptr);
offset += ptr - start;
end -= ptr - start;
ptr = start;
offset += ptr - start;
end -= ptr - start;
ptr = start;
}
while (avail() < needed) {
if (!fillBuffer(start + bufSize - end, wait))