Skip to content

Commit

Permalink
optimize: remove unneeded fmt printing
Browse files Browse the repository at this point in the history
~458 ns/op -> ~303 ns/op
  • Loading branch information
felixge committed Jan 11, 2015
1 parent 0bce954 commit 473330a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions xxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 473330a

Please sign in to comment.