Preallocate space for the answer in Base58Encode.

Benchmarks show this makes Base58Encode twice as fast.
This commit is contained in:
David Hill 2014-04-16 20:43:01 -04:00
parent e622fde7e7
commit 190c86b2bf

View file

@ -53,7 +53,7 @@ func Base58Encode(b []byte) string {
x := new(big.Int)
x.SetBytes(b)
answer := make([]byte, 0)
answer := make([]byte, 0, len(b)*136/100)
for x.Cmp(bigZero) > 0 {
mod := new(big.Int)
x.DivMod(x, bigRadix, mod)