From de7723c7a0f2a4e086de5ad5b6bd7ceac074df46 Mon Sep 17 00:00:00 2001 From: PekingSpades <180665176+PekingSpades@users.noreply.github.com> Date: Sat, 13 Dec 2025 11:10:12 +0800 Subject: [PATCH] Inline DataView reads in rQshift methods --- core/websock.js | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/core/websock.js b/core/websock.js index 42de1664..f920406e 100644 --- a/core/websock.js +++ b/core/websock.js @@ -105,43 +105,21 @@ export default class Websock { } rQshift8() { - return this._rQshift(1); + const offset = this._rQi; + this._rQi += 1; + return this._rQdv.getUint8(offset); } rQshift16() { - return this._rQshift(2); + const offset = this._rQi; + this._rQi += 2; + return this._rQdv.getUint16(offset, false); } rQshift32() { - return this._rQshift(4); - } - - // Use DataView for faster integer reads (with a fallback for uncommon sizes) - _rQshift(bytes) { - if (!this._rQdv && this._rQ) { - this._rQdv = new DataView(this._rQ.buffer); - } - - if (this._rQdv && (bytes === 1 || bytes === 2 || bytes === 4)) { - const offset = this._rQi; - this._rQi += bytes; - - let res; - if (bytes === 1) { - res = this._rQdv.getUint8(offset); - } else if (bytes === 2) { - res = this._rQdv.getUint16(offset, false); - } else { - res = this._rQdv.getUint32(offset, false); - } - return res >>> 0; - } - - let res = 0; - for (let byte = bytes - 1; byte >= 0; byte--) { - res += this._rQ[this._rQi++] << (byte * 8); - } - return res >>> 0; + const offset = this._rQi; + this._rQi += 4; + return this._rQdv.getUint32(offset, false); } rQlen() {