Skip to content

Commit dce3bca

Browse files
committed
optimize: remove printf for hex encoding
~208 ns/op now
1 parent 1208045 commit dce3bca

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

xxd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"bufio"
5+
"encoding/hex"
56
"fmt"
67
"io"
78
"os"
@@ -48,7 +49,7 @@ func XXD(r io.Reader, w io.Writer) error {
4849

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

5354
if i%2 == 1 {
5455
io.WriteString(w, " ")

0 commit comments

Comments
 (0)