Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04d80f8

Browse files
author
Skip Montanaro
committed
small speedup for constant and name access
see sf #506436
1 parent 1ee99d3 commit 04d80f8

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

Python/ceval.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ eval_frame(PyFrameObject *f)
494494
PyThreadState *tstate = PyThreadState_GET();
495495
PyCodeObject *co;
496496
unsigned char *first_instr;
497+
PyObject *names;
498+
PyObject *consts;
497499
#ifdef LLTRACE
498500
int lltrace;
499501
#endif
@@ -512,8 +514,7 @@ eval_frame(PyFrameObject *f)
512514

513515
/* Code access macros */
514516

515-
#define GETCONST(i) (GETITEM(co->co_consts, (i)))
516-
#define GETNAMEV(i) (GETITEM(co->co_names, (i)))
517+
#define GETNAMEV(i) (GETITEM(names, (i)))
517518
#define INSTR_OFFSET() (next_instr - first_instr)
518519
#define NEXTOP() (*next_instr++)
519520
#define NEXTARG() (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2])
@@ -575,6 +576,8 @@ eval_frame(PyFrameObject *f)
575576

576577
tstate->frame = f;
577578
co = f->f_code;
579+
names = co->co_names;
580+
consts = co->co_consts;
578581
fastlocals = f->f_localsplus;
579582
freevars = f->f_localsplus + f->f_nlocals;
580583
_PyCode_GETCODEPTR(co, &first_instr);
@@ -753,7 +756,7 @@ eval_frame(PyFrameObject *f)
753756
break;
754757

755758
case LOAD_CONST:
756-
x = GETCONST(oparg);
759+
x = GETITEM(consts, oparg);
757760
Py_INCREF(x);
758761
PUSH(x);
759762
goto fast_next_opcode;

0 commit comments

Comments
 (0)