From 879e33ab64d7038720b183568b4377753b1b5a0e Mon Sep 17 00:00:00 2001 From: Juanjo Diaz Date: Sat, 8 Dec 2018 17:32:00 +0200 Subject: [PATCH] Extract rQshift to common function --- core/websock.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/core/websock.js b/core/websock.js index 71a331bc..51b9a66f 100644 --- a/core/websock.js +++ b/core/websock.js @@ -75,22 +75,24 @@ export default class Websock { } rQshift8() { - return this._rQ[this._rQi++]; + return this._rQshift(1); } - - - // TODO(directxman12): test performance with these vs a DataView rQshift16() { - return (this._rQ[this._rQi++] << 8) + - this._rQ[this._rQi++]; + return this._rQshift(2); } rQshift32() { - return (this._rQ[this._rQi++] << 24) + - (this._rQ[this._rQi++] << 16) + - (this._rQ[this._rQi++] << 8) + - this._rQ[this._rQi++]; + return this._rQshift(4); + } + + // TODO(directxman12): test performance with these vs a DataView + _rQshift(bytes) { + let res = 0; + for (let byte = bytes - 1; byte >= 0; byte--) { + res += this._rQ[this._rQi++] << (byte * 8); + } + return res; } rQshiftStr(len) {