From 4516e7d1bce5e749f1a6fd7dce3be0ee1feed142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Anda=20Estensen?= Date: Tue, 6 Dec 2022 17:53:32 +0100 Subject: [PATCH] Improve performance of token compilation (#12) --- core/asm/compiler.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/asm/compiler.go b/core/asm/compiler.go index ce2d23abd0ba..4c2af78c8162 100644 --- a/core/asm/compiler.go +++ b/core/asm/compiler.go @@ -17,6 +17,7 @@ package asm import ( + "encoding/hex" "fmt" "math/big" "os" @@ -106,12 +107,13 @@ func (c *Compiler) Compile() (string, []error) { // turn the binary to hex var bin strings.Builder + bin.Grow(len(c.binary)) for _, v := range c.binary { switch v := v.(type) { case vm.OpCode: - bin.WriteString(fmt.Sprintf("%x", []byte{byte(v)})) + bin.WriteString(hex.EncodeToString([]byte{byte(v)})) case []byte: - bin.WriteString(fmt.Sprintf("%x", v)) + bin.WriteString(hex.EncodeToString(v)) } } return bin.String(), errors