Skip to content

Commit cbcb957

Browse files
author
James Cor
committed
bytes from string
1 parent b9da4b4 commit cbcb957

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

sql/types/enum.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func (t EnumType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes
289289
}
290290

291291
// TODO: write append style encoder
292-
res, ok := charset.Encoder().Encode(encodings.StringToBytes(value)) // TODO: use unsafe string to byte
292+
res, ok := charset.Encoder().Encode([]byte(value))
293293
if !ok {
294294
if len(value) > 50 {
295295
value = value[:50]

sql/types/time.go

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -507,30 +507,39 @@ func (t Timespan) AppendBytes(dest []byte) []byte {
507507
if microseconds > 0 {
508508
sz += 7
509509
}
510-
511-
i := 0
512510
if isNegative {
513511
dest = append(dest, '-')
514-
i++
515512
}
516513

517-
i = appendDigit(int64(hours), 2, dest, i)
518-
dest[i] = ':'
519-
i++
520-
i = appendDigit(int64(minutes), 2, dest, i)
521-
dest[i] = ':'
522-
i++
523-
i = appendDigit(int64(seconds), 2, dest, i)
524-
if microseconds > 0 {
525-
dest[i] = '.'
526-
i++
527-
i = appendDigit(int64(microseconds), 6, dest, i)
514+
if hours < 10 {
515+
dest = append(dest, '0')
528516
}
517+
dest = strconv.AppendInt(dest, int64(hours), 10)
518+
dest = append(dest, ':')
529519

530-
return dest[:i]
520+
if minutes < 10 {
521+
dest = append(dest, '0')
522+
}
523+
dest = strconv.AppendInt(dest, int64(minutes), 10)
524+
dest = append(dest, ':')
525+
526+
if seconds < 10 {
527+
dest = append(dest, '0')
528+
}
529+
dest = strconv.AppendInt(dest, int64(seconds), 10)
530+
if microseconds > 0 {
531+
dest = append(dest, '.')
532+
cmp := int32(100000)
533+
for cmp > 0 && microseconds < cmp {
534+
dest = append(dest, '0')
535+
cmp /= 10
536+
}
537+
dest = strconv.AppendInt(dest, int64(microseconds), 10)
538+
}
539+
return dest
531540
}
532541

533-
// appendDigit format prints 0-entended integer into buffer
542+
// appendDigit format prints 0-extended integer into buffer
534543
func appendDigit(v int64, extend int, buf []byte, i int) int {
535544
cmp := int64(1)
536545
for _ = range extend - 1 {

0 commit comments

Comments
 (0)