Skip to content

Commit

Permalink
Avoid expensive fmt.Fprintf calls in StringWriter.Write inner loop.
Browse files Browse the repository at this point in the history
This addresses issue 14.
  • Loading branch information
Jim Teeuwen committed Jan 29, 2014
1 parent ae22b84 commit e87a807
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions stringwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
package bindata

import (
"fmt"
"io"
)

const lowerHex = "0123456789abcdef"

type StringWriter struct {
io.Writer
c int
Expand All @@ -19,8 +20,13 @@ func (w *StringWriter) Write(p []byte) (n int, err error) {
return
}

for n = range p {
fmt.Fprintf(w.Writer, "\\x%02x", p[n])
buf := []byte(`\x00`)
var b byte

for n, b = range p {
buf[2] = lowerHex[b/16]
buf[3] = lowerHex[b%16]
w.Writer.Write(buf)
w.c++
}

Expand Down

0 comments on commit e87a807

Please sign in to comment.