]> Cypherpunks repositories - gostls13.git/commit
encoding: optimize growth behavior in Encoding.AppendDecode
authorJoe Tsai <joetsai@digital-static.net>
Thu, 17 Aug 2023 04:27:15 +0000 (21:27 -0700)
committerGopher Robot <gobot@golang.org>
Sat, 19 Aug 2023 22:25:23 +0000 (22:25 +0000)
commite8cdab5c494716e547d2b84b68d46680e35a7a9f
tree6d6c704c354a6c2137d95824098e6f34d6c0c496
parente47fad515d50f685677b7418ae3fc24a0849f663
encoding: optimize growth behavior in Encoding.AppendDecode

The Encoding.DecodedLen API only returns the maximum length of the
expected decoded output, since it does not know about padding.
Since we have the input, we can do better by computing the
input length without padding, and then perform the DecodedLen
calculation as if there were no padding.

This avoids over-growing the destination slice if possible.
Over-growth is still possible since the input may contain
ignore characters like newlines and carriage returns,
but those a rarely encountered in practice.

Change-Id: I38b8f91de1f4fbd3a7128c491a25098bd385cf74
Reviewed-on: https://go-review.googlesource.com/c/go/+/520267
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/encoding/base32/base32.go
src/encoding/base32/base32_test.go
src/encoding/base64/base64.go
src/encoding/base64/base64_test.go