Do not allocate result in heap in decodeChunk

This commit is contained in:
DataHoarder 2023-05-27 14:09:33 +02:00
parent 369ce9f705
commit 71018b5b4d
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk

View file

@ -59,15 +59,15 @@ func encodeChunk(raw []byte, padding int, buf []byte) []byte {
return buf
}
func decodeChunk(buf []byte, encoded string) (result []byte) {
func decodeChunk(buf []byte, encoded string) []byte {
var bigResult uint128.Uint128
currentMultiplier := uint128.From64(1)
for i := len(encoded) - 1; i >= 0; i-- {
bigResult = bigResult.Add(currentMultiplier.Mul64(uint64(fastBase58Lookup(encoded[i]))))
currentMultiplier = currentMultiplier.Mul64(58)
}
result = make([]byte, 16)
bigResult.ReverseBytes().PutBytes(result)
var result [16]byte
bigResult.ReverseBytes().PutBytes(result[:])
switch len(encoded) {
case 0:
return append(buf, result[8+8:]...)