From dfa0c9095505f447e04ddea32939ee8c5f876699 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Mon, 10 May 2021 14:35:45 -0700 Subject: [PATCH] internal/deepprint: replace Fprintf(w, const) with w.WriteString MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit name old time/op new time/op delta Hash-8 7.77µs ± 0% 6.29µs ± 1% -19.11% (p=0.000 n=9+10) name old alloc/op new alloc/op delta Hash-8 1.67kB ± 0% 1.67kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta Hash-8 53.0 ± 0% 53.0 ± 0% ~ (all equal) Signed-off-by: Josh Bleecher Snyder --- internal/deepprint/deepprint.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/internal/deepprint/deepprint.go b/internal/deepprint/deepprint.go index f0e93980c..ddc48d2fc 100644 --- a/internal/deepprint/deepprint.go +++ b/internal/deepprint/deepprint.go @@ -132,14 +132,14 @@ func print(w *bufio.Writer, v reflect.Value, visited map[uintptr]bool) { print(w, v.Elem(), visited) return case reflect.Struct: - fmt.Fprintf(w, "struct{\n") + w.WriteString("struct{\n") t := v.Type() for i, n := 0, v.NumField(); i < n; i++ { sf := t.Field(i) w.WriteString(sf.Name) w.WriteString(": ") print(w, v.Field(i), visited) - fmt.Fprintf(w, "\n") + w.WriteString("\n") } case reflect.Slice, reflect.Array: if v.Type().Elem().Kind() == reflect.Uint8 && v.CanInterface() { @@ -150,9 +150,9 @@ func print(w *bufio.Writer, v reflect.Value, visited map[uintptr]bool) { for i, ln := 0, v.Len(); i < ln; i++ { fmt.Fprintf(w, " [%d]: ", i) print(w, v.Index(i), visited) - fmt.Fprintf(w, "\n") + w.WriteString("\n") } - fmt.Fprintf(w, "}\n") + w.WriteString("}\n") case reflect.Interface: print(w, v.Elem(), visited) case reflect.Map: @@ -160,12 +160,11 @@ func print(w *bufio.Writer, v reflect.Value, visited map[uintptr]bool) { fmt.Fprintf(w, "map[%d]{\n", len(sm.Key)) for i, k := range sm.Key { print(w, k, visited) - fmt.Fprintf(w, ": ") + w.WriteString(": ") print(w, sm.Value[i], visited) - fmt.Fprintf(w, "\n") + w.WriteString("\n") } - fmt.Fprintf(w, "}\n") - + w.WriteString("}\n") case reflect.String: w.WriteString(v.String()) case reflect.Bool: