Skip to content

Commit

Permalink
Updated iota.
Browse files Browse the repository at this point in the history
  • Loading branch information
d2g committed Apr 15, 2015
1 parent 96c55c3 commit 305e535
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions capture.go
Expand Up @@ -341,21 +341,18 @@ func (l *Logger) Write(p []byte) (int, error) {
}

// Cheap integer to fixed-width decimal ASCII. Give a negative width to avoid zero-padding.
// Knows the buffer has capacity.
func itoa(buf *[]byte, i int, wid int) {
var u uint = uint(i)
if u == 0 && wid <= 1 {
*buf = append(*buf, '0')
return
}

// Assemble decimal in reverse order.
var b [32]byte
bp := len(b)
for ; u > 0 || wid > 0; u /= 10 {
bp--
var b [20]byte
bp := len(b) - 1
for i >= 10 || wid > 1 {
wid--
b[bp] = byte(u%10) + '0'
q := i / 10
b[bp] = byte('0' + i - q*10)
bp--
i = q
}

b[bp] = byte('0' + i)
*buf = append(*buf, b[bp:]...)
}

0 comments on commit 305e535

Please sign in to comment.