From: apocelipes Date: Tue, 26 Mar 2024 06:44:26 +0000 (+0000) Subject: encoding/asn1: simplify appendFourDigits X-Git-Tag: go1.23rc1~750 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=33fd95b8203f1ac887f13e7381a7ff124d098258;p=gostls13.git encoding/asn1: simplify appendFourDigits The new code does not need a for-loop and is easier to read. Change-Id: Ic182d63c4779c2179b721fcfaec362681284cc16 GitHub-Last-Rev: b3ee265df7eb4d51c945bf5453eb1b09f91912d9 GitHub-Pull-Request: golang/go#63879 Reviewed-on: https://go-review.googlesource.com/c/go/+/538721 Auto-Submit: Keith Randall Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall Reviewed-by: Than McIntosh --- diff --git a/src/encoding/asn1/marshal.go b/src/encoding/asn1/marshal.go index d8c8fe17b3..69ab4f6f9e 100644 --- a/src/encoding/asn1/marshal.go +++ b/src/encoding/asn1/marshal.go @@ -355,12 +355,11 @@ func appendTwoDigits(dst []byte, v int) []byte { } func appendFourDigits(dst []byte, v int) []byte { - var bytes [4]byte - for i := range bytes { - bytes[3-i] = '0' + byte(v%10) - v /= 10 - } - return append(dst, bytes[:]...) + return append(dst, + byte('0'+(v/1000)%10), + byte('0'+(v/100)%10), + byte('0'+(v/10)%10), + byte('0'+v%10)) } func outsideUTCRange(t time.Time) bool {