Avoid expensive fmt.Fprintf calls in `StringWriter.Write` inner loop.

This addresses issue 14.
pull/4/head v3.0.4
Jim Teeuwen 2014-01-29 11:34:37 +01:00
parent ae22b84b7e
commit e87a807885
1 changed files with 9 additions and 3 deletions

View File

@ -5,10 +5,11 @@
package bindata package bindata
import ( import (
"fmt"
"io" "io"
) )
const lowerHex = "0123456789abcdef"
type StringWriter struct { type StringWriter struct {
io.Writer io.Writer
c int c int
@ -19,8 +20,13 @@ func (w *StringWriter) Write(p []byte) (n int, err error) {
return return
} }
for n = range p { buf := []byte(`\x00`)
fmt.Fprintf(w.Writer, "\\x%02x", p[n]) var b byte
for n, b = range p {
buf[2] = lowerHex[b/16]
buf[3] = lowerHex[b%16]
w.Writer.Write(buf)
w.c++ w.c++
} }