Skip to content

Commit

Permalink
bn: make .strip() an internal method (see #105)
Browse files Browse the repository at this point in the history
  • Loading branch information
axic authored and indutny committed Nov 29, 2017
1 parent da8516f commit e88e7b7
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions lib/bn.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
this.negative = 1;
}

this.strip();
this._strip();

if (endian !== 'le') return;

Expand Down Expand Up @@ -180,7 +180,7 @@
}
}
}
return this.strip();
return this._strip();
};

function parseHex (str, start, end) {
Expand Down Expand Up @@ -234,7 +234,7 @@
this.words[j] |= (w << off) & 0x3ffffff;
this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
}
this.strip();
this._strip();
};

function parseBase (str, start, end, mul) {
Expand Down Expand Up @@ -333,7 +333,7 @@
};

// Remove leading `0` from `this`
BN.prototype.strip = function strip () {
BN.prototype._strip = function strip () {
while (this.length > 1 && this.words[this.length - 1] === 0) {
this.length--;
}
Expand Down Expand Up @@ -530,7 +530,7 @@
assert(byteLength <= reqLength, 'byte array longer than desired length');
assert(reqLength > 0, 'Requested array length <= 0');

this.strip();
this._strip();
var littleEndian = endian === 'le';
var res = allocate(ArrayType, reqLength);

Expand Down Expand Up @@ -705,7 +705,7 @@
this.words[i] = this.words[i] | num.words[i];
}

return this.strip();
return this._strip();
};

BN.prototype.ior = function ior (num) {
Expand Down Expand Up @@ -740,7 +740,7 @@

this.length = b.length;

return this.strip();
return this._strip();
};

BN.prototype.iand = function iand (num) {
Expand Down Expand Up @@ -784,7 +784,7 @@

this.length = a.length;

return this.strip();
return this._strip();
};

BN.prototype.ixor = function ixor (num) {
Expand Down Expand Up @@ -828,7 +828,7 @@
}

// And remove leading zeroes
return this.strip();
return this._strip();
};

BN.prototype.notn = function notn (width) {
Expand All @@ -850,7 +850,7 @@
this.words[off] = this.words[off] & ~(1 << wbit);
}

return this.strip();
return this._strip();
};

// Add `num` to `this` in-place
Expand Down Expand Up @@ -991,7 +991,7 @@
this.negative = 1;
}

return this.strip();
return this._strip();
};

// Subtract `num` from `this`
Expand Down Expand Up @@ -1037,7 +1037,7 @@
out.length--;
}

return out.strip();
return out._strip();
}

// TODO(indutny): it may be reasonable to omit it for users who don't need
Expand Down Expand Up @@ -1659,7 +1659,7 @@
out.length--;
}

return out.strip();
return out._strip();
}

function jumboMulTo (self, num, out) {
Expand Down Expand Up @@ -1876,7 +1876,7 @@

out.negative = x.negative ^ y.negative;
out.length = x.length + y.length;
return out.strip();
return out._strip();
};

// Multiply `this` by `num`
Expand Down Expand Up @@ -1994,7 +1994,7 @@
this.length += s;
}

return this.strip();
return this._strip();
};

BN.prototype.ishln = function ishln (bits) {
Expand Down Expand Up @@ -2060,7 +2060,7 @@
this.length = 1;
}

return this.strip();
return this._strip();
};

BN.prototype.ishrn = function ishrn (bits, hint, extended) {
Expand Down Expand Up @@ -2125,7 +2125,7 @@
this.words[this.length - 1] &= mask;
}

return this.strip();
return this._strip();
};

// Return only lowers bits of number
Expand Down Expand Up @@ -2200,7 +2200,7 @@
}
}

return this.strip();
return this._strip();
};

BN.prototype.addn = function addn (num) {
Expand Down Expand Up @@ -2242,7 +2242,7 @@
this.words[i + shift] = w & 0x3ffffff;
}

if (carry === 0) return this.strip();
if (carry === 0) return this._strip();

// Subtraction overflow
assert(carry === -1);
Expand All @@ -2254,7 +2254,7 @@
}
this.negative = 1;

return this.strip();
return this._strip();
};

BN.prototype._wordDiv = function _wordDiv (num, mode) {
Expand Down Expand Up @@ -2316,9 +2316,9 @@
}
}
if (q) {
q.strip();
q._strip();
}
a.strip();
a._strip();

// Denormalize
if (mode !== 'div' && shift !== 0) {
Expand Down Expand Up @@ -2492,7 +2492,7 @@
carry = w % num;
}

return this.strip();
return this._strip();
};

BN.prototype.divn = function divn (num) {
Expand Down Expand Up @@ -2744,7 +2744,7 @@
if (this.negative !== 0 && !negative) return -1;
if (this.negative === 0 && negative) return 1;

this.strip();
this._strip();

var res;
if (this.length > 1) {
Expand Down Expand Up @@ -2987,7 +2987,7 @@
} else if (cmp > 0) {
r.isub(this.p);
} else {
r.strip();
r._strip();
}

return r;
Expand Down

0 comments on commit e88e7b7

Please sign in to comment.