encoding: no casting.

This commit is contained in:
Christopher Jeffrey 2016-12-02 06:36:12 -08:00
parent c190dd2aad
commit 89f478bba1
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -56,8 +56,6 @@ encoding.MAX_SAFE_ADDITION = 0xfffffffffffff;
encoding._readU64 = function _readU64(data, off, force53, be) {
var hi, lo;
off = off >>> 0;
if (be) {
hi = data.readUInt32BE(off, true);
lo = data.readUInt32BE(off + 4, true);
@ -136,8 +134,6 @@ encoding.readU53BE = function readU53BE(data, off) {
encoding._read64 = function _read64(data, off, force53, be) {
var hi, lo;
off = off >>> 0;
if (be) {
hi = data.readUInt32BE(off, true);
lo = data.readUInt32BE(off + 4, true);
@ -226,13 +222,8 @@ encoding.read53BE = function read53BE(data, off) {
*/
encoding._write64 = function _write64(dst, num, off, be) {
var negative, hi, lo;
assert(typeof num === 'number');
off = off >>> 0;
negative = num < 0;
var negative = num < 0;
var hi, lo;
if (negative) {
num = -num;
@ -334,9 +325,7 @@ encoding.write64BE = function write64BE(dst, num, off) {
*/
encoding.readU64BN = function readU64BN(data, off) {
var num;
off = off >>> 0;
num = data.slice(off, off + 8);
var num = data.slice(off, off + 8);
return new BN(num, 'le');
};
@ -348,9 +337,7 @@ encoding.readU64BN = function readU64BN(data, off) {
*/
encoding.readU64BEBN = function readU64BEBN(data, off) {
var num;
off = off >>> 0;
num = data.slice(off, off + 8);
var num = data.slice(off, off + 8);
return new BN(num, 'be');
};
@ -362,11 +349,7 @@ encoding.readU64BEBN = function readU64BEBN(data, off) {
*/
encoding.read64BN = function read64BN(data, off) {
var num;
off = off >>> 0;
num = data.slice(off, off + 8);
var num = data.slice(off, off + 8);
if (num[num.length - 1] & 0x80)
return new BN(num, 'le').notn(64).addn(1).neg();
@ -381,11 +364,7 @@ encoding.read64BN = function read64BN(data, off) {
*/
encoding.read64BEBN = function read64BEBN(data, off) {
var num;
off = off >>> 0;
num = data.slice(off, off + 8);
var num = data.slice(off, off + 8);
if (num[0] & 0x80)
return new BN(num, 'be').notn(64).addn(1).neg();
@ -409,8 +388,6 @@ encoding._write64BN = function _write64BN(dst, num, off, be) {
if (num.bitLength() <= 53)
return encoding._write64(dst, num.toNumber(), off, be);
off = off >>> 0;
if (num.bitLength() > 64)
num = num.uand(encoding.U64_MAX);
@ -483,8 +460,6 @@ encoding.write64BEBN = function write64BEBN(dst, num, off) {
encoding.readVarint = function readVarint(data, off) {
var value, size;
off = off >>> 0;
assert(off < data.length);
switch (data[off]) {
@ -524,10 +499,6 @@ encoding.readVarint = function readVarint(data, off) {
*/
encoding.writeVarint = function writeVarint(dst, num, off) {
off = off >>> 0;
num = +num;
if (num < 0xfd) {
dst[off++] = num & 0xff;
return off;
@ -562,8 +533,6 @@ encoding.writeVarint = function writeVarint(dst, num, off) {
*/
encoding.skipVarint = function skipVarint(data, off) {
off = off >>> 0;
assert(off < data.length);
switch (data[off]) {
@ -607,8 +576,6 @@ encoding.sizeVarint = function sizeVarint(num) {
encoding.readVarintBN = function readVarintBN(data, off) {
var value, size;
off = off >>> 0;
assert(off < data.length);
switch (data[off]) {
@ -632,8 +599,6 @@ encoding.readVarintBN = function readVarintBN(data, off) {
*/
encoding.writeVarintBN = function writeVarintBN(dst, num, off) {
off = off >>> 0;
if (num.bitLength() > 32) {
dst[off] = 0xff;
encoding.writeU64(dst, num, off + 1);
@ -668,8 +633,6 @@ encoding.readVarint2 = function readVarint2(data, off) {
var size = 0;
var ch;
off = off >>> 0;
for (;;) {
assert(off < data.length);
@ -701,9 +664,6 @@ encoding.writeVarint2 = function writeVarint2(dst, num, off) {
var tmp = [];
var len = 0;
off = off >>> 0;
num = +num;
for (;;) {
tmp[len] = (num & 0x7f) | (len ? 0x80 : 0x00);
if (num <= 0x7f)
@ -732,8 +692,6 @@ encoding.skipVarint2 = function skipVarint2(data, off) {
var size = 0;
var ch;
off = off >>> 0;
for (;;) {
assert(off < data.length);
ch = data[off++];
@ -754,8 +712,6 @@ encoding.skipVarint2 = function skipVarint2(data, off) {
encoding.sizeVarint2 = function sizeVarint2(num) {
var size = 0;
num = +num;
for (;;) {
size++;
if (num <= 0x7f)
@ -778,8 +734,6 @@ encoding.readVarint2BN = function readVarint2BN(data, off) {
var size = 0;
var ch;
off = off >>> 0;
while (num < 0x3fffffffffff) {
assert(off < data.length);