Skip to content

Commit a3be381

Browse files
authored
core/vm: performance tweak of OpCode.String() (#28453)
make `opCodeToString` a `[256]string` array Co-authored-by: lmittmann <[email protected]>
1 parent f4ac548 commit a3be381

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

core/vm/opcodes.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ const (
224224
SELFDESTRUCT OpCode = 0xff
225225
)
226226

227-
// Since the opcodes aren't all in order we can't use a regular slice.
228-
var opCodeToString = map[OpCode]string{
227+
var opCodeToString = [256]string{
229228
// 0x0 range - arithmetic ops.
230229
STOP: "STOP",
231230
ADD: "ADD",
@@ -399,12 +398,10 @@ var opCodeToString = map[OpCode]string{
399398
}
400399

401400
func (op OpCode) String() string {
402-
str := opCodeToString[op]
403-
if len(str) == 0 {
404-
return fmt.Sprintf("opcode %#x not defined", int(op))
401+
if s := opCodeToString[op]; s != "" {
402+
return s
405403
}
406-
407-
return str
404+
return fmt.Sprintf("opcode %#x not defined", int(op))
408405
}
409406

410407
var stringToOp = map[string]OpCode{

0 commit comments

Comments
 (0)