Do not allocate result in heap in decodeChunk
This commit is contained in:
parent
369ce9f705
commit
71018b5b4d
|
@ -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:]...)
|
||||
|
|
Reference in a new issue