From 43cd31ea9f57e26f8f67aa8bd03bbb0a50814465 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet Date: Thu, 8 Oct 2020 14:03:24 +0200 Subject: [PATCH] core/vm: dedup config check in markdown logger (#21655) * core/vm: dedup config check * review feedback: reuse buffer --- core/vm/logger.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/vm/logger.go b/core/vm/logger.go index e1d7c67ef..3b166b5d2 100644 --- a/core/vm/logger.go +++ b/core/vm/logger.go @@ -322,20 +322,21 @@ func (t *mdLogger) CaptureStart(from common.Address, to common.Address, create b func (t *mdLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, rStack *ReturnStack, rData []byte, contract *Contract, depth int, err error) error { fmt.Fprintf(t.out, "| %4d | %10v | %3d |", pc, op, cost) - if !t.cfg.DisableStack { // format stack + if !t.cfg.DisableStack { + // format stack var a []string for _, elem := range stack.data { a = append(a, fmt.Sprintf("%d", elem)) } b := fmt.Sprintf("[%v]", strings.Join(a, ",")) fmt.Fprintf(t.out, "%10v |", b) - } - if !t.cfg.DisableStack { // format return stack - var a []string + + // format return stack + a = a[:0] for _, elem := range rStack.data { a = append(a, fmt.Sprintf("%2d", elem)) } - b := fmt.Sprintf("[%v]", strings.Join(a, ",")) + b = fmt.Sprintf("[%v]", strings.Join(a, ",")) fmt.Fprintf(t.out, "%10v |", b) } fmt.Fprintln(t.out, "")