Skip to content

Commit 0268c80

Browse files
committed
optimize the performance of the function appendFormatRFC3339
1 parent 7b578d0 commit 0268c80

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/time/format_rfc3339.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ func (t Time) appendFormatRFC3339(b []byte, nanos bool) []byte {
5353
b = append(b, '+')
5454
}
5555

56+
if zone > 3600 {
57+
b = appendInt(b, zone/60, 2)
58+
b = append(b, ':')
59+
b = appendInt(b, zone%60, 2)
60+
return b
61+
}
62+
5663
zone %= 3600
5764
b = append(b,
5865
tensDigit[zone/60], onesDigit[zone/60],

src/time/format_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,7 @@ func BenchmarkAppendIntWidth4(b *testing.B) {
11231123
func BenchmarkTimeFormatRFC3339(b *testing.B) {
11241124
tm := Unix(1661201140, 676836973)
11251125
buf := make([]byte, 0, 64)
1126+
b.ReportAllocs()
11261127
for b.Loop() {
11271128
buf = tm.AppendFormat(buf[:0], RFC3339)
11281129
}

0 commit comments

Comments
 (0)