[go: nahoru, domu]

Skip to content

Commit

Permalink
Extract rQshift to common function
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjoDiaz committed Dec 8, 2018
1 parent 8a189a6 commit 879e33a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions core/websock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 879e33a

Please sign in to comment.