From 08a80d74d515737322516fb55151083752f26c25 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Mon, 29 Jun 2015 23:51:03 -0400 Subject: [PATCH] more optimizations for readUInt64lebn --- lib/encoding/bufferreader.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/encoding/bufferreader.js b/lib/encoding/bufferreader.js index a730a61..73f351d 100644 --- a/lib/encoding/bufferreader.js +++ b/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; };