more optimizations for readUInt64lebn

This commit is contained in:
Braydon Fuller 2015-06-29 23:51:03 -04:00
parent 805182c500
commit 08a80d74d5
1 changed files with 10 additions and 2 deletions

View File

@ -91,8 +91,16 @@ BufferReader.prototype.readUInt64BEBN = function() {
};
BufferReader.prototype.readUInt64LEBN = function() {
var data = Array.prototype.slice.call(this.buf, this.pos, this.pos + 8);
var bn = new BN(data, 10, 'le');
var second = this.buf.readUInt32LE(this.pos);
var first = this.buf.readUInt32LE(this.pos + 4);
var combined = (first * 0x100000000) + second;
var bn;
if (combined <= 0x1fffffffffffff) {
bn = new BN(combined);
} else {
var data = Array.prototype.slice.call(this.buf, this.pos, this.pos + 8);
bn = new BN(data, 10, 'le');
}
this.pos = this.pos + 8;
return bn;
};