Comparing version 1.2.0 to 1.2.1
@@ -0,1 +1,5 @@ | ||
1.2.1 / 2014-07-24 | ||
------------------ | ||
* speed optimizations [Daniel Cousens / #8](https://github.com/cryptocoinjs/bs58/pull/8) | ||
1.2.0 / 2014-06-29 | ||
@@ -2,0 +6,0 @@ ------------------ |
@@ -23,7 +23,9 @@ // Base58 encoding/decoding | ||
for (j = 0; j < digits.length; j++) digits[j] <<= 8 | ||
digits[digits.length - 1] += buffer[i] | ||
digits[0] += buffer[i] | ||
var carry = 0 | ||
for (j = digits.length - 1; j >= 0; j--){ | ||
for (j = 0; j < digits.length; ++j) { | ||
digits[j] += carry | ||
carry = (digits[j] / BASE) | 0 | ||
@@ -34,5 +36,5 @@ digits[j] %= BASE | ||
while (carry) { | ||
digits.unshift(carry) | ||
carry = (digits[0] / BASE) | 0 | ||
digits[0] %= BASE | ||
digits.push(carry % BASE) | ||
carry = (carry / BASE) | 0 | ||
} | ||
@@ -42,5 +44,5 @@ } | ||
// deal with leading zeros | ||
for (i = 0; i < buffer.length - 1 && buffer[i] == 0; i++) digits.unshift(0) | ||
for (i = 0; i < buffer.length - 1 && buffer[i] == 0; i++) digits.push(0) | ||
return digits.map(function(digit) { return ALPHABET[digit] }).join('') | ||
return digits.reverse().map(function(digit) { return ALPHABET[digit] }).join('') | ||
} | ||
@@ -52,3 +54,3 @@ | ||
var input = string.split('').map(function(c){ | ||
assert.notEqual(ALPHABET_MAP[c], undefined, 'Non-base58 character') | ||
assert(c in ALPHABET_MAP, 'Non-base58 character') | ||
return ALPHABET_MAP[c] | ||
@@ -60,7 +62,8 @@ }) | ||
for (j = 0; j < bytes.length; j++) bytes[j] *= BASE | ||
bytes[bytes.length - 1] += input[i] | ||
bytes[0] += input[i] | ||
var carry = 0 | ||
for (j = bytes.length - 1; j >= 0; j--){ | ||
for (j = 0; j < bytes.length; ++j) { | ||
bytes[j] += carry | ||
carry = bytes[j] >> 8 | ||
@@ -71,5 +74,5 @@ bytes[j] &= 0xff | ||
while (carry) { | ||
bytes.unshift(carry) | ||
carry = bytes[0] >> 8 | ||
bytes[0] &= 0xff | ||
bytes.push(carry & 0xff) | ||
carry >>= 8 | ||
} | ||
@@ -79,5 +82,5 @@ } | ||
// deal with leading zeros | ||
for (i = 0; i < input.length - 1 && input[i] == 0; i++) bytes.unshift(0) | ||
for (i = 0; i < input.length - 1 && input[i] == 0; i++) bytes.push(0) | ||
return new Buffer(bytes) | ||
return new Buffer(bytes.reverse()) | ||
} | ||
@@ -84,0 +87,0 @@ |
{ | ||
"name": "bs58", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Base 58 encoding / decoding", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
5356
63