Skip to content

Commit

Permalink
optimize: remove printf for hex encoding
Browse files Browse the repository at this point in the history
~208 ns/op now
  • Loading branch information
felixge committed Jan 11, 2015
1 parent 1208045 commit dce3bca
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion xxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"encoding/hex"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -48,7 +49,7 @@ func XXD(r io.Reader, w io.Writer) error {

// Hex values
for i := 0; i < n; i++ {
fmt.Fprintf(w, "%02x", buf[i])
io.WriteString(w, hex.EncodeToString(buf[i:i+1]))

if i%2 == 1 {
io.WriteString(w, " ")
Expand Down

0 comments on commit dce3bca

Please sign in to comment.