Merge pull request #19446 from Snuffleupagus/shorten-MeshStreamReader-readBits
Shorten the `MeshStreamReader.prototype.readBits` method a little bit
This commit is contained in:
commit
8ba8e75d6c
@ -340,24 +340,19 @@ class MeshStreamReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
readBits(n) {
|
readBits(n) {
|
||||||
let buffer = this.buffer;
|
const { stream } = this;
|
||||||
let bufferLength = this.bufferLength;
|
let { buffer, bufferLength } = this;
|
||||||
|
|
||||||
if (n === 32) {
|
if (n === 32) {
|
||||||
if (bufferLength === 0) {
|
if (bufferLength === 0) {
|
||||||
return (
|
return stream.getInt32() >>> 0;
|
||||||
((this.stream.getByte() << 24) |
|
|
||||||
(this.stream.getByte() << 16) |
|
|
||||||
(this.stream.getByte() << 8) |
|
|
||||||
this.stream.getByte()) >>>
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
buffer =
|
buffer =
|
||||||
(buffer << 24) |
|
(buffer << 24) |
|
||||||
(this.stream.getByte() << 16) |
|
(stream.getByte() << 16) |
|
||||||
(this.stream.getByte() << 8) |
|
(stream.getByte() << 8) |
|
||||||
this.stream.getByte();
|
stream.getByte();
|
||||||
const nextByte = this.stream.getByte();
|
const nextByte = stream.getByte();
|
||||||
this.buffer = nextByte & ((1 << bufferLength) - 1);
|
this.buffer = nextByte & ((1 << bufferLength) - 1);
|
||||||
return (
|
return (
|
||||||
((buffer << (8 - bufferLength)) |
|
((buffer << (8 - bufferLength)) |
|
||||||
@ -366,10 +361,10 @@ class MeshStreamReader {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (n === 8 && bufferLength === 0) {
|
if (n === 8 && bufferLength === 0) {
|
||||||
return this.stream.getByte();
|
return stream.getByte();
|
||||||
}
|
}
|
||||||
while (bufferLength < n) {
|
while (bufferLength < n) {
|
||||||
buffer = (buffer << 8) | this.stream.getByte();
|
buffer = (buffer << 8) | stream.getByte();
|
||||||
bufferLength += 8;
|
bufferLength += 8;
|
||||||
}
|
}
|
||||||
bufferLength -= n;
|
bufferLength -= n;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user