1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 17:48:07 +02:00

Allocate fewer objects when parsing 2 and 4 byte chunks.

This is achieved by adding getBytes2() and getBytes4() to streams, and by
changing int16() and int32() to take multiple scalar args instead of an array
arg.
This commit is contained in:
Nicholas Nethercote 2014-03-11 21:09:49 -07:00
parent e5cd75083f
commit 6a75e45309
3 changed files with 101 additions and 64 deletions

View file

@ -40,6 +40,18 @@ var Stream = (function StreamClosure() {
return -1;
return this.bytes[this.pos++];
},
getUint16: function Stream_getUint16() {
var b0 = this.getByte();
var b1 = this.getByte();
return (b0 << 8) + b1;
},
getUint32: function Stream_getUint32() {
var b0 = this.getByte();
var b1 = this.getByte();
var b2 = this.getByte();
var b3 = this.getByte();
return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
},
// returns subarray of original buffer
// should only be read
getBytes: function Stream_getBytes(length) {
@ -143,6 +155,18 @@ var DecodeStream = (function DecodeStreamClosure() {
}
return this.buffer[this.pos++];
},
getUint16: function DecodeStream_getUint16() {
var b0 = this.getByte();
var b1 = this.getByte();
return (b0 << 8) + b1;
},
getUint32: function DecodeStream_getUint32() {
var b0 = this.getByte();
var b1 = this.getByte();
var b2 = this.getByte();
var b3 = this.getByte();
return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
},
getBytes: function DecodeStream_getBytes(length) {
var end, pos = this.pos;