mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Shorten the MeshStreamReader.prototype.readBits
method a little bit
- Use a `BaseStream`-instance method to directly get the int32 value. - Use local variables more.
This commit is contained in:
parent
72339dc561
commit
36522d85cc
1 changed files with 10 additions and 15 deletions
|
@ -340,24 +340,19 @@ class MeshStreamReader {
|
|||
}
|
||||
|
||||
readBits(n) {
|
||||
let buffer = this.buffer;
|
||||
let bufferLength = this.bufferLength;
|
||||
const { stream } = this;
|
||||
let { buffer, bufferLength } = this;
|
||||
|
||||
if (n === 32) {
|
||||
if (bufferLength === 0) {
|
||||
return (
|
||||
((this.stream.getByte() << 24) |
|
||||
(this.stream.getByte() << 16) |
|
||||
(this.stream.getByte() << 8) |
|
||||
this.stream.getByte()) >>>
|
||||
0
|
||||
);
|
||||
return stream.getInt32() >>> 0;
|
||||
}
|
||||
buffer =
|
||||
(buffer << 24) |
|
||||
(this.stream.getByte() << 16) |
|
||||
(this.stream.getByte() << 8) |
|
||||
this.stream.getByte();
|
||||
const nextByte = this.stream.getByte();
|
||||
(stream.getByte() << 16) |
|
||||
(stream.getByte() << 8) |
|
||||
stream.getByte();
|
||||
const nextByte = stream.getByte();
|
||||
this.buffer = nextByte & ((1 << bufferLength) - 1);
|
||||
return (
|
||||
((buffer << (8 - bufferLength)) |
|
||||
|
@ -366,10 +361,10 @@ class MeshStreamReader {
|
|||
);
|
||||
}
|
||||
if (n === 8 && bufferLength === 0) {
|
||||
return this.stream.getByte();
|
||||
return stream.getByte();
|
||||
}
|
||||
while (bufferLength < n) {
|
||||
buffer = (buffer << 8) | this.stream.getByte();
|
||||
buffer = (buffer << 8) | stream.getByte();
|
||||
bufferLength += 8;
|
||||
}
|
||||
bufferLength -= n;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue