From 08567b08acecf94fb65db6b2038b68fec7ea1c66 Mon Sep 17 00:00:00 2001 From: Jesper Alf Dam Date: Wed, 7 Aug 2019 11:12:35 +0200 Subject: [PATCH] When compacting the receive buffer don't copy unused buffer space When compacting the receive buffer, we should only copy the bytes between _rQi and _rQlen (the index of the first unread byte, and the next write position). Previously, we copied everything for _rQi up untill the end of the buffer. --- core/websock.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/websock.js b/core/websock.js index 252f3529..c8d90acb 100644 --- a/core/websock.js +++ b/core/websock.js @@ -247,12 +247,12 @@ export default class Websock { if (resizeNeeded) { const old_rQbuffer = this._rQ.buffer; this._rQ = new Uint8Array(this._rQbufferSize); - this._rQ.set(new Uint8Array(old_rQbuffer, this._rQi)); + this._rQ.set(new Uint8Array(old_rQbuffer, this._rQi, this._rQlen - this._rQi)); } else { if (ENABLE_COPYWITHIN) { - this._rQ.copyWithin(0, this._rQi); + this._rQ.copyWithin(0, this._rQi, this._rQlen); } else { - this._rQ.set(new Uint8Array(this._rQ.buffer, this._rQi)); + this._rQ.set(new Uint8Array(this._rQ.buffer, this._rQi, this._rQlen - this._rQi)); } }