Skip to content
This repository was archived by the owner on Sep 19, 2018. It is now read-only.

Commit e87a807

Browse files
author
Jim Teeuwen
committed
Avoid expensive fmt.Fprintf calls in StringWriter.Write inner loop.
This addresses issue 14.
1 parent ae22b84 commit e87a807

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

stringwriter.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
package bindata
66

77
import (
8-
"fmt"
98
"io"
109
)
1110

11+
const lowerHex = "0123456789abcdef"
12+
1213
type StringWriter struct {
1314
io.Writer
1415
c int
@@ -19,8 +20,13 @@ func (w *StringWriter) Write(p []byte) (n int, err error) {
1920
return
2021
}
2122

22-
for n = range p {
23-
fmt.Fprintf(w.Writer, "\\x%02x", p[n])
23+
buf := []byte(`\x00`)
24+
var b byte
25+
26+
for n, b = range p {
27+
buf[2] = lowerHex[b/16]
28+
buf[3] = lowerHex[b%16]
29+
w.Writer.Write(buf)
2430
w.c++
2531
}
2632

0 commit comments

Comments
 (0)