Skip to content

Commit

Permalink
core/vm: performance tweak of OpCode.String() (ethereum#28453)
Browse files Browse the repository at this point in the history
make `opCodeToString` a `[256]string` array

Co-authored-by: lmittmann <[email protected]>
  • Loading branch information
2 people authored and colinlyguo committed Oct 31, 2024
1 parent 6142999 commit 20e567b
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions core/vm/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ const (
SELFDESTRUCT OpCode = 0xff
)

// Since the opcodes aren't all in order we can't use a regular slice.
var opCodeToString = map[OpCode]string{
var opCodeToString = [256]string{
// 0x0 range - arithmetic ops.
STOP: "STOP",
ADD: "ADD",
Expand Down Expand Up @@ -401,12 +400,10 @@ var opCodeToString = map[OpCode]string{
}

func (op OpCode) String() string {
str := opCodeToString[op]
if len(str) == 0 {
return fmt.Sprintf("opcode %#x not defined", int(op))
if s := opCodeToString[op]; s != "" {
return s
}

return str
return fmt.Sprintf("opcode %#x not defined", int(op))
}

var stringToOp = map[string]OpCode{
Expand Down

0 comments on commit 20e567b

Please sign in to comment.