Preallocate for common case in base58 decode, expose preallocated case

This commit is contained in:
DataHoarder 2023-05-24 16:15:34 +02:00
parent a566889a4d
commit 113843a69c
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk

View file

@ -91,6 +91,12 @@ func EncodeMoneroBase58(data ...[]byte) string {
}
func DecodeMoneroBase58(data string) (result []byte) {
//common case
return DecodeMoneroBase58PreAllocated(make([]byte, 0, 69), data)
}
func DecodeMoneroBase58PreAllocated(buf []byte, data string) (result []byte) {
result = buf
length := len(data)
rounds := length / 11
for i := 0; i < rounds; i++ {