Replace QuoRem / Mul with QuoRem64 / Mul64 alternatives
This commit is contained in:
parent
7d37dcb5ae
commit
369ce9f705
10
base58.go
10
base58.go
|
@ -41,16 +41,14 @@ func fastBase58Lookup(c uint8) uint8 {
|
|||
return 0
|
||||
}
|
||||
|
||||
var base128 = uint128.From64(58)
|
||||
|
||||
func encodeChunk(raw []byte, padding int, buf []byte) []byte {
|
||||
var data [16]byte
|
||||
copy(data[16-len(raw):], raw)
|
||||
remainder := uint128.FromBytesBE(data[:])
|
||||
var current uint128.Uint128
|
||||
var current uint64
|
||||
for remainder.Cmp64(0) > 0 {
|
||||
remainder, current = remainder.QuoRem(base128)
|
||||
buf = append(buf, BASE58[current.Lo])
|
||||
remainder, current = remainder.QuoRem64(58)
|
||||
buf = append(buf, BASE58[current])
|
||||
}
|
||||
for len(buf) < padding {
|
||||
buf = append(buf, '1')
|
||||
|
@ -66,7 +64,7 @@ func decodeChunk(buf []byte, encoded string) (result []byte) {
|
|||
currentMultiplier := uint128.From64(1)
|
||||
for i := len(encoded) - 1; i >= 0; i-- {
|
||||
bigResult = bigResult.Add(currentMultiplier.Mul64(uint64(fastBase58Lookup(encoded[i]))))
|
||||
currentMultiplier = currentMultiplier.Mul(base128)
|
||||
currentMultiplier = currentMultiplier.Mul64(58)
|
||||
}
|
||||
result = make([]byte, 16)
|
||||
bigResult.ReverseBytes().PutBytes(result)
|
||||
|
|
Reference in a new issue