|
1 | 1 | package bilog
|
2 | 2 |
|
3 |
| -import "strconv" |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "strconv" |
| 6 | + "unsafe" |
| 7 | +) |
4 | 8 |
|
5 | 9 | // 快速格式化年月日
|
6 | 10 | // year之外的数字如果小于10则会使用零填充prefix
|
@@ -96,3 +100,31 @@ func fastConvertMinute(i int) string {
|
96 | 100 | func fastConvertSecond(i int) string {
|
97 | 101 | return secondBuf[i]
|
98 | 102 | }
|
| 103 | + |
| 104 | +// 返回存储时间的字节数组和写入数据的有效数量 |
| 105 | +func fastConvertAllToArray(year, month, day, hour, minute, second int) (tmp [32]byte, eff int) { |
| 106 | + data := (uintptr)(unsafe.Pointer(&tmp)) |
| 107 | + slice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{ |
| 108 | + Data: data, |
| 109 | + Len: 0, |
| 110 | + Cap: len(tmp), |
| 111 | + })) |
| 112 | + slice = append(slice, fastConvertYear(year)...) |
| 113 | + slice = append(slice, fastConvertMonth(month)...) |
| 114 | + slice = append(slice, fastConvertDay(day)...) |
| 115 | + slice = append(slice, fastConvertHour(hour)...) |
| 116 | + slice = append(slice, fastConvertMinute(minute)...) |
| 117 | + slice = append(slice, fastConvertSecond(second)...) |
| 118 | + return tmp, len(slice) |
| 119 | +} |
| 120 | + |
| 121 | +func fastConvertAllToSlice(year, month, day, hour, minute, second int) []byte { |
| 122 | + tmp := make([]byte, 0, 32) |
| 123 | + tmp = append(tmp, fastConvertYear(year)...) |
| 124 | + tmp = append(tmp, fastConvertMonth(month)...) |
| 125 | + tmp = append(tmp, fastConvertDay(day)...) |
| 126 | + tmp = append(tmp, fastConvertHour(hour)...) |
| 127 | + tmp = append(tmp, fastConvertMinute(minute)...) |
| 128 | + tmp = append(tmp, fastConvertSecond(second)...) |
| 129 | + return tmp |
| 130 | +} |
0 commit comments