diff --git a/lib/bn.js b/lib/bn.js index 9e81596..8d9312e 100644 --- a/lib/bn.js +++ b/lib/bn.js @@ -530,7 +530,7 @@ this.strip(); var littleEndian = endian === 'le'; - var res = new ArrayType(reqLength); + var res = allocate(ArrayType, reqLength); var b, i; var q = this.clone(); @@ -562,6 +562,13 @@ return res; }; + var allocate = function allocate (ArrayType, size) { + if (ArrayType.allocUnsafe) { + return ArrayType.allocUnsafe(size); + } + return new ArrayType(size); + }; + if (Math.clz32) { BN.prototype._countBits = function _countBits (w) { return 32 - Math.clz32(w);