Skip to content

Commit 55f00fd

Browse files
committed
optimize the performance of the function appendFormatRFC3339
1 parent 8509192 commit 55f00fd

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/time/format_rfc3339.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,21 @@ func (t Time) appendFormatRFC3339(b []byte, nanos bool) []byte {
2020

2121
// Format date.
2222
year, month, day := abs.days().date()
23-
b = appendIntWidth4(b, year)
24-
b = append(b, '-',
25-
tensDigit[month], onesDigit[month], '-',
26-
tensDigit[day], onesDigit[day])
27-
28-
b = append(b, 'T')
29-
3023
// Format time.
3124
hour, min, sec := abs.clock()
32-
b = append(b,
33-
tensDigit[hour], onesDigit[hour], ':',
34-
tensDigit[min], onesDigit[min], ':',
35-
tensDigit[sec], onesDigit[sec])
25+
26+
b = appendIntWidth4(b, year)
27+
b = append(b, '-',
28+
tensDigit[month], onesDigit[month],
29+
'-',
30+
tensDigit[day], onesDigit[day],
31+
'T',
32+
tensDigit[hour], onesDigit[hour],
33+
':',
34+
tensDigit[min], onesDigit[min],
35+
':',
36+
tensDigit[sec], onesDigit[sec],
37+
)
3638

3739
if nanos {
3840
std := stdFracSecond(stdFracSecond9, 9, '.')
@@ -54,8 +56,10 @@ func (t Time) appendFormatRFC3339(b []byte, nanos bool) []byte {
5456

5557
zone %= 3600
5658
b = append(b,
57-
tensDigit[zone/60], onesDigit[zone/60], ':',
58-
tensDigit[zone%60], onesDigit[zone%60])
59+
tensDigit[zone/60], onesDigit[zone/60],
60+
':',
61+
tensDigit[zone%60], onesDigit[zone%60],
62+
)
5963
return b
6064
}
6165

0 commit comments

Comments
 (0)