1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #19446 from Snuffleupagus/shorten-MeshStreamReader-readBits

Shorten the `MeshStreamReader.prototype.readBits` method a little bit
This commit is contained in:
Tim van der Meij 2025-02-09 12:57:53 +01:00 committed by GitHub
commit 8ba8e75d6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;