From 6354386d6568e83e0c81c745e79223b570673fe7 Mon Sep 17 00:00:00 2001
From: Neil Schemenauer <nascheme@enme.ucalgary.ca>
Date: Sun, 17 Feb 2002 19:10:14 +0000
Subject: Move some opcodes to top of big eval_frame switch statement.  Skip
 things_to_do block for a few common opcodes that don't do any real work. 
 Closes SF patch #512256.

---
 Python/ceval.c | 89 +++++++++++++++++++++++++++++-----------------------------
 1 file changed, 45 insertions(+), 44 deletions(-)

diff --git a/Python/ceval.c b/Python/ceval.c
index 202c868..dc00e42 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -680,6 +680,7 @@ eval_frame(PyFrameObject *f)
 #endif
 		}
 
+	fast_next_opcode:
 		/* Extract opcode and argument */
 
 #if defined(Py_DEBUG) || defined(LLTRACE)
@@ -724,10 +725,53 @@ eval_frame(PyFrameObject *f)
 
 		/* case STOP_CODE: this is an error! */
 
+		case SET_LINENO:
+#ifdef LLTRACE
+			if (lltrace)
+				printf("--- %s:%d \n", filename, oparg);
+#endif
+			f->f_lineno = oparg;
+			if (tstate->c_tracefunc == NULL || tstate->tracing)
+				goto fast_next_opcode;
+			/* Trace each line of code reached */
+			f->f_lasti = INSTR_OFFSET();
+			/* Inline call_trace() for performance: */
+			tstate->tracing++;
+			tstate->use_tracing = 0;
+			err = (tstate->c_tracefunc)(tstate->c_traceobj, f,
+						    PyTrace_LINE, Py_None);
+			tstate->use_tracing = (tstate->c_tracefunc
+					       || tstate->c_profilefunc);
+			tstate->tracing--;
+			break;
+
+		case LOAD_FAST:
+			x = GETLOCAL(oparg);
+			if (x != NULL) {
+				Py_INCREF(x);
+				PUSH(x);
+				goto fast_next_opcode;
+			}
+			format_exc_check_arg(PyExc_UnboundLocalError,
+				UNBOUNDLOCAL_ERROR_MSG,
+				PyTuple_GetItem(co->co_varnames, oparg));
+			break;
+
+		case LOAD_CONST:
+			x = GETCONST(oparg);
+			Py_INCREF(x);
+			PUSH(x);
+			goto fast_next_opcode;
+
+		case STORE_FAST:
+			v = POP();
+			SETLOCAL(oparg, v);
+			goto fast_next_opcode;
+
 		case POP_TOP:
 			v = POP();
 			Py_DECREF(v);
-			continue;
+			goto fast_next_opcode;
 
 		case ROT_TWO:
 			v = POP();
@@ -1617,12 +1661,6 @@ eval_frame(PyFrameObject *f)
 				    PyExc_NameError, GLOBAL_NAME_ERROR_MSG, w);
 			break;
 
-		case LOAD_CONST:
-			x = GETCONST(oparg);
-			Py_INCREF(x);
-			PUSH(x);
-			break;
-
 		case LOAD_NAME:
 			w = GETNAMEV(oparg);
 			if ((x = f->f_locals) == NULL) {
@@ -1664,23 +1702,6 @@ eval_frame(PyFrameObject *f)
 			PUSH(x);
 			break;
 
-		case LOAD_FAST:
-			x = GETLOCAL(oparg);
-			if (x != NULL) {
-				Py_INCREF(x);
-				PUSH(x);
-				continue;
-			}
-			format_exc_check_arg(PyExc_UnboundLocalError,
-				UNBOUNDLOCAL_ERROR_MSG,
-				PyTuple_GetItem(co->co_varnames, oparg));
-			break;
-
-		case STORE_FAST:
-			v = POP();
-			SETLOCAL(oparg, v);
-			continue;
-
 		case DELETE_FAST:
 			x = GETLOCAL(oparg);
 			if (x == NULL) {
@@ -1949,26 +1970,6 @@ eval_frame(PyFrameObject *f)
 					   STACK_LEVEL());
 			continue;
 
-		case SET_LINENO:
-#ifdef LLTRACE
-			if (lltrace)
-				printf("--- %s:%d \n", filename, oparg);
-#endif
-			f->f_lineno = oparg;
-			if (tstate->c_tracefunc == NULL || tstate->tracing)
-				continue;
-			/* Trace each line of code reached */
-			f->f_lasti = INSTR_OFFSET();
-			/* Inline call_trace() for performance: */
-			tstate->tracing++;
-			tstate->use_tracing = 0;
-			err = (tstate->c_tracefunc)(tstate->c_traceobj, f,
-						    PyTrace_LINE, Py_None);
-			tstate->use_tracing = (tstate->c_tracefunc
-					       || tstate->c_profilefunc);
-			tstate->tracing--;
-			break;
-
 		case CALL_FUNCTION:
 		{
 		    int na = oparg & 0xff;
-- 
cgit v0.12

