internal/deepprint: replace Fprintf(w, const) with w.WriteString

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 <josh@tailscale.com>
This commit is contained in:
Josh Bleecher Snyder 2021-05-10 14:35:45 -07:00 committed by Josh Bleecher Snyder
parent d4f805339e
commit dfa0c90955
1 changed files with 7 additions and 8 deletions

View File

@ -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: