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

Skip to content

Commit 1dd8309

Browse files
committed
SF patch #864059: optimize eval_frame
Simplified version of Neal Norwitz's patch which adds gotos for opcodes that set "why". This skips a number of tests where the outcome of the tests are known in advance.
1 parent 7dcf9f8 commit 1dd8309

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

Python/ceval.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,12 +1578,12 @@ eval_frame(PyFrameObject *f)
15781578
#endif
15791579
case BREAK_LOOP:
15801580
why = WHY_BREAK;
1581-
break;
1581+
goto fast_block_end;
15821582

15831583
case CONTINUE_LOOP:
15841584
retval = PyInt_FromLong(oparg);
15851585
why = WHY_CONTINUE;
1586-
break;
1586+
goto fast_block_end;
15871587

15881588
case RAISE_VARARGS:
15891589
u = v = w = NULL;
@@ -1620,14 +1620,13 @@ eval_frame(PyFrameObject *f)
16201620
case RETURN_VALUE:
16211621
retval = POP();
16221622
why = WHY_RETURN;
1623-
break;
1623+
goto fast_block_end;
16241624

16251625
case YIELD_VALUE:
16261626
retval = POP();
16271627
f->f_stacktop = stack_pointer;
16281628
why = WHY_YIELD;
1629-
break;
1630-
1629+
goto fast_yield;
16311630

16321631
case EXEC_STMT:
16331632
w = TOP();
@@ -2327,6 +2326,7 @@ eval_frame(PyFrameObject *f)
23272326

23282327
/* Unwind stacks if a (pseudo) exception occurred */
23292328

2329+
fast_block_end:
23302330
while (why != WHY_NOT && why != WHY_YIELD && f->f_iblock > 0) {
23312331
PyTryBlock *b = PyFrame_BlockPop(f);
23322332

@@ -2410,6 +2410,7 @@ eval_frame(PyFrameObject *f)
24102410
if (why != WHY_RETURN && why != WHY_YIELD)
24112411
retval = NULL;
24122412

2413+
fast_yield:
24132414
if (tstate->use_tracing) {
24142415
if (tstate->c_tracefunc
24152416
&& (why == WHY_RETURN || why == WHY_YIELD)) {

0 commit comments

Comments
 (0)