Browse Source

more optimizations for readUInt64lebn

patch-2
Braydon Fuller 10 years ago
parent
commit
08a80d74d5
  1. 12
      lib/encoding/bufferreader.js

12
lib/encoding/bufferreader.js

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

Loading…
Cancel
Save