From 473330acd320e5318e896d6408fb3d64a5b8e10b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Sun, 11 Jan 2015 16:35:52 +0100 Subject: [PATCH] optimize: remove unneeded fmt printing ~458 ns/op -> ~303 ns/op --- xxd.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/xxd.go b/xxd.go index d6c0952..87796c2 100644 --- a/xxd.go +++ b/xxd.go @@ -51,31 +51,31 @@ func XXD(r io.Reader, w io.Writer) error { fmt.Fprintf(w, "%02x", buf[i]) if i%2 == 1 { - fmt.Fprint(w, " ") + io.WriteString(w, " ") } } if n < len(buf) { for i := n; i < len(buf); i++ { - fmt.Fprintf(w, " ") + io.WriteString(w, " ") if i%2 == 1 { - fmt.Fprint(w, " ") + io.WriteString(w, " ") } } } - fmt.Fprintf(w, " ") + io.WriteString(w, " ") // Character values b := buf[:n] for _, c := range b { if c > 0x1f && c < 0x7f { - fmt.Fprintf(w, "%v", string(c)) + io.WriteString(w, string(c)) } else { - fmt.Fprintf(w, ".") + io.WriteString(w, ".") } } - fmt.Fprintf(w, "\n") + io.WriteString(w, "\n") } return nil }