Skip to content

Commit fe01fcf

Browse files
author
Jesper Alf Dam
committed
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.
1 parent 1a450fc commit fe01fcf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

core/websock.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,12 @@ export default class Websock {
247247
if (resizeNeeded) {
248248
const old_rQbuffer = this._rQ.buffer;
249249
this._rQ = new Uint8Array(this._rQbufferSize);
250-
this._rQ.set(new Uint8Array(old_rQbuffer, this._rQi));
250+
this._rQ.set(new Uint8Array(old_rQbuffer, this._rQi, this._rQlen - this._rQi));
251251
} else {
252252
if (ENABLE_COPYWITHIN) {
253-
this._rQ.copyWithin(0, this._rQi);
253+
this._rQ.copyWithin(0, this._rQi, this._rQlen);
254254
} else {
255-
this._rQ.set(new Uint8Array(this._rQ.buffer, this._rQi));
255+
this._rQ.set(new Uint8Array(this._rQ.buffer, this._rQi, this._rQlen - this._rQi));
256256
}
257257
}
258258

0 commit comments

Comments
 (0)