From 8368bac847c4cdae9d2ecd652a28a19662bdd50a Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Mon, 10 May 2021 17:51:25 -0700 Subject: [PATCH] internal/deepprint: stop printing struct field names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The struct field names don't change within a single run, so they are irrelevant. Use the field index instead. name old time/op new time/op delta Hash-8 6.52µs ± 0% 6.64µs ± 0% +1.91% (p=0.000 n=6+9) name old alloc/op new alloc/op delta Hash-8 1.67kB ± 0% 1.54kB ± 0% -7.66% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Hash-8 53.0 ± 0% 37.0 ± 0% -30.19% (p=0.000 n=10+10) Signed-off-by: Josh Bleecher Snyder --- internal/deepprint/deepprint.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/internal/deepprint/deepprint.go b/internal/deepprint/deepprint.go index ddc48d2fc..ef846fce6 100644 --- a/internal/deepprint/deepprint.go +++ b/internal/deepprint/deepprint.go @@ -133,11 +133,8 @@ func print(w *bufio.Writer, v reflect.Value, visited map[uintptr]bool) { return case reflect.Struct: 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(": ") + fmt.Fprintf(w, " [%d]: ", i) print(w, v.Field(i), visited) w.WriteString("\n") }