From 190c86b2bf950a75783ea1d5d855f57c0c1b03da Mon Sep 17 00:00:00 2001 From: David Hill Date: Wed, 16 Apr 2014 20:43:01 -0400 Subject: [PATCH] Preallocate space for the answer in Base58Encode. Benchmarks show this makes Base58Encode twice as fast. --- base58.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base58.go b/base58.go index a199510..a94d38a 100644 --- a/base58.go +++ b/base58.go @@ -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)