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 devopsbo3 committed Nov 10, 2023
1 parent cc68033 commit 0622724
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 @@ -224,8 +224,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 @@ -399,12 +398,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 0622724

Please sign in to comment.