Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff -cr Python-2.7.6/Include/opcode.h Python-2.7.6-patched/Include/opcode.h
*** Python-2.7.6/Include/opcode.h 2013-11-10 08:36:39.000000000 +0100
--- Python-2.7.6-patched/Include/opcode.h 2014-05-16 16:14:42.885966107 +0200
***************
*** 149,154 ****
--- 149,155 ----
#define SET_ADD 146
#define MAP_ADD 147
+ #define LOAD_FAST_ZERO_LOAD_CONST 148
enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE, PyCmp_GT=Py_GT, PyCmp_GE=Py_GE,
diff -cr Python-2.7.6/Python/ceval.c Python-2.7.6-patched/Python/ceval.c
*** Python-2.7.6/Python/ceval.c 2013-11-10 08:36:41.000000000 +0100
--- Python-2.7.6-patched/Python/ceval.c 2014-05-16 18:50:55.326163474 +0200
***************
*** 1125,1130 ****
--- 1125,1144 ----
Py_INCREF(x);
PUSH(x);
goto fast_next_opcode;
+ case LOAD_FAST_ZERO_LOAD_CONST:
+ x = GETLOCAL(0);
+ if (x != NULL) {
+ Py_INCREF(x);
+ PUSH(x);
+ x = GETITEM(consts, oparg);
+ 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;
PREDICTED_WITH_ARG(STORE_FAST);
case STORE_FAST:
diff -cr Python-2.7.6/Python/peephole.c Python-2.7.6-patched/Python/peephole.c
*** Python-2.7.6/Python/peephole.c 2013-11-10 08:36:41.000000000 +0100
--- Python-2.7.6-patched/Python/peephole.c 2014-05-16 16:28:03.493936033 +0200
***************
*** 422,427 ****
--- 422,435 ----
memset(codestr+i, NOP, 6);
cumlc = 0;
break;
+ case LOAD_FAST:
+ {
+ j = GETARG(codestr, i);
+ if (codestr[i+3] == LOAD_CONST && j == 0) {
+ codestr[i+3] = LOAD_FAST_ZERO_LOAD_CONST;
+ memset(codestr+i, NOP, 3);
+ }
+ } break;
/* Try to fold tuples of constants (includes a case for lists
which are only used for "in" and "not in" tests).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment