diff options
author | Benjamin Peterson <benjamin@python.org> | 2012-12-06 22:41:04 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2012-12-06 22:41:04 (GMT) |
commit | 442f20996dcd994d1024e5cad7f66a4595352eb2 (patch) | |
tree | 641746efd4247acd2b5e13f5de7f65c026242a05 /Python/peephole.c | |
parent | 4b237e3b1112304f834ac78fe05abdecbf3d87b4 (diff) | |
download | cpython-442f20996dcd994d1024e5cad7f66a4595352eb2.zip cpython-442f20996dcd994d1024e5cad7f66a4595352eb2.tar.gz cpython-442f20996dcd994d1024e5cad7f66a4595352eb2.tar.bz2 |
create NameConstant AST class for None, True, and False literals (closes #16619)
Diffstat (limited to 'Python/peephole.c')
-rw-r--r-- | Python/peephole.c | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/Python/peephole.c b/Python/peephole.c index 5d53677..e6877bb 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -327,37 +327,6 @@ markblocks(unsigned char *code, Py_ssize_t len) return blocks; } -/* Helper to replace LOAD_NAME None/True/False with LOAD_CONST - Returns: 0 if no change, 1 if change, -1 if error */ -static int -load_global(unsigned char *codestr, Py_ssize_t i, char *name, PyObject *consts) -{ - Py_ssize_t j; - PyObject *obj; - if (name == NULL) - return 0; - if (strcmp(name, "None") == 0) - obj = Py_None; - else if (strcmp(name, "True") == 0) - obj = Py_True; - else if (strcmp(name, "False") == 0) - obj = Py_False; - else - return 0; - for (j = 0; j < PyList_GET_SIZE(consts); j++) { - if (PyList_GET_ITEM(consts, j) == obj) - break; - } - if (j == PyList_GET_SIZE(consts)) { - if (PyList_Append(consts, obj) < 0) - return -1; - } - assert(PyList_GET_ITEM(consts, j) == obj); - codestr[i] = LOAD_CONST; - SETARG(codestr, i, j); - return 1; -} - /* Perform basic peephole optimizations to components of a code object. The consts object should still be in list form to allow new constants to be appended. @@ -392,7 +361,6 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, Py_ssize_t const_stack_size = 0; int in_consts = 0; /* whether we are in a LOAD_CONST sequence */ unsigned int *blocks = NULL; - char *name; /* Bail out if an exception is set */ if (PyErr_Occurred()) @@ -475,20 +443,6 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, codestr[i+3] = NOP; break; - /* Replace LOAD_GLOBAL/LOAD_NAME None/True/False - with LOAD_CONST None/True/False */ - case LOAD_NAME: - case LOAD_GLOBAL: - j = GETARG(codestr, i); - name = _PyUnicode_AsString(PyTuple_GET_ITEM(names, j)); - h = load_global(codestr, i, name, consts); - if (h < 0) - goto exitError; - else if (h == 0) - continue; - CONST_STACK_PUSH_OP(i); - break; - /* Skip over LOAD_CONST trueconst POP_JUMP_IF_FALSE xx. This improves "while 1" performance. */ |