From c2bbdb573d546eb88539d1204b84cb48d910191a Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Sat, 16 May 2020 11:32:26 +0200 Subject: [PATCH] Don't shuffle input buffer unless actually needed --- common/rdr/BufferedInStream.cxx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/common/rdr/BufferedInStream.cxx b/common/rdr/BufferedInStream.cxx index 64cdb667..967e5a54 100644 --- a/common/rdr/BufferedInStream.cxx +++ b/common/rdr/BufferedInStream.cxx @@ -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)) -- 2.39.5