@@ -467,30 +467,35 @@ func (t Timespan) String() string {
467467
468468func (t Timespan ) Bytes () []byte {
469469 isNegative , hours , minutes , seconds , microseconds := t .timespanToUnits ()
470- ret := make ([]byte , 1000 )
470+ sz := 10
471+ if microseconds > 0 {
472+ sz += 7
473+ }
474+ ret := make ([]byte , sz )
471475 i := 0
472476 if isNegative {
473477 ret [0 ] = '-'
474478 i ++
475479 }
476480
477- i = printDigit (int64 (hours ), 2 , ret , i )
481+ i = appendDigit (int64 (hours ), 2 , ret , i )
478482 ret [i ] = ':'
479483 i ++
480- i = printDigit (int64 (minutes ), 2 , ret , i )
484+ i = appendDigit (int64 (minutes ), 2 , ret , i )
481485 ret [i ] = ':'
482486 i ++
483- i = printDigit (int64 (seconds ), 2 , ret , i )
487+ i = appendDigit (int64 (seconds ), 2 , ret , i )
484488 if microseconds > 0 {
485489 ret [i ] = '.'
486490 i ++
487- i = printDigit (int64 (microseconds ), 6 , ret , i )
491+ i = appendDigit (int64 (microseconds ), 6 , ret , i )
488492 }
489493
490494 return ret [:i ]
491495}
492496
493- func printDigit (v int64 , extend int , buf []byte , i int ) int {
497+ // appendDigit format prints 0-entended integer into buffer
498+ func appendDigit (v int64 , extend int , buf []byte , i int ) int {
494499 cmp := int64 (1 )
495500 for _ = range extend - 1 {
496501 cmp *= 10
0 commit comments