mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 12:40:55 +00:00
format time header 5% faster than before
This commit is contained in:
parent
8e82ed319b
commit
99436a75b1
@ -36,43 +36,44 @@ func (lg *logWriter) println(when time.Time, msg string) {
|
||||
lg.Unlock()
|
||||
}
|
||||
|
||||
const y1 = `0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999`
|
||||
const y2 = `0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789`
|
||||
const mo1 = `000000000111`
|
||||
const mo2 = `123456789012`
|
||||
const d1 = `0000000001111111111222222222233`
|
||||
const d2 = `1234567890123456789012345678901`
|
||||
const h1 = `000000000011111111112222`
|
||||
const h2 = `012345678901234567890123`
|
||||
const mi1 = `000000000011111111112222222222333333333344444444445555555555`
|
||||
const mi2 = `012345678901234567890123456789012345678901234567890123456789`
|
||||
const s1 = `000000000011111111112222222222333333333344444444445555555555`
|
||||
const s2 = `012345678901234567890123456789012345678901234567890123456789`
|
||||
|
||||
func formatTimeHeader(when time.Time) ([]byte, int) {
|
||||
y, mo, d := when.Date()
|
||||
h, mi, s := when.Clock()
|
||||
//len(2006/01/02 15:03:04)==19
|
||||
//len("2006/01/02 15:03:04 ")==20
|
||||
var buf [20]byte
|
||||
t := 3
|
||||
for y >= 10 {
|
||||
p := y / 10
|
||||
buf[t] = byte('0' + y - p*10)
|
||||
y = p
|
||||
t--
|
||||
}
|
||||
buf[0] = byte('0' + y)
|
||||
|
||||
buf[0] = '2'
|
||||
buf[1] = '0'
|
||||
buf[2] = y1[y-2000]
|
||||
buf[3] = y2[y-2000]
|
||||
buf[4] = '/'
|
||||
if mo > 9 {
|
||||
buf[5] = '1'
|
||||
buf[6] = byte('0' + mo - 9)
|
||||
} else {
|
||||
buf[5] = '0'
|
||||
buf[6] = byte('0' + mo)
|
||||
}
|
||||
buf[5] = mo1[mo]
|
||||
buf[6] = mo2[mo]
|
||||
buf[7] = '/'
|
||||
t = d / 10
|
||||
buf[8] = byte('0' + t)
|
||||
buf[9] = byte('0' + d - t*10)
|
||||
buf[8] = d1[d]
|
||||
buf[9] = d2[d]
|
||||
buf[10] = ' '
|
||||
t = h / 10
|
||||
buf[11] = byte('0' + t)
|
||||
buf[12] = byte('0' + h - t*10)
|
||||
buf[11] = h1[h]
|
||||
buf[12] = h2[h]
|
||||
buf[13] = ':'
|
||||
t = mi / 10
|
||||
buf[14] = byte('0' + t)
|
||||
buf[15] = byte('0' + mi - t*10)
|
||||
buf[14] = mi1[mi]
|
||||
buf[15] = mi2[mi]
|
||||
buf[16] = ':'
|
||||
t = s / 10
|
||||
buf[17] = byte('0' + t)
|
||||
buf[18] = byte('0' + s - t*10)
|
||||
buf[17] = s1[s]
|
||||
buf[18] = s2[s]
|
||||
buf[19] = ' '
|
||||
|
||||
return buf[0:], d
|
||||
|
Loading…
Reference in New Issue
Block a user