aboutsummaryrefslogtreecommitdiffstats
path: root/common/rdr/BufferedInStream.cxx
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2020-05-16 11:32:26 +0200
committerPierre Ossman <ossman@cendio.se>2020-05-21 11:34:22 +0200
commitc2bbdb573d546eb88539d1204b84cb48d910191a (patch)
tree8a28f0e3892e9789c6f37113a116d456cac98dec /common/rdr/BufferedInStream.cxx
parentd7a61c7df39c25945e1aa5f7843e8f3681ed7169 (diff)
downloadtigervnc-c2bbdb573d546eb88539d1204b84cb48d910191a.tar.gz
tigervnc-c2bbdb573d546eb88539d1204b84cb48d910191a.zip
Don't shuffle input buffer unless actually needed
Diffstat (limited to 'common/rdr/BufferedInStream.cxx')
-rw-r--r--common/rdr/BufferedInStream.cxx10
1 files 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))