diff -r c8ce5bca0fcd Python/ceval.c --- a/Python/ceval.c Tue Jul 15 12:29:11 2014 -0700 +++ b/Python/ceval.c Mon Jul 21 20:30:01 2014 -0600 @@ -1561,6 +1561,25 @@ sum = unicode_concatenate(left, right, f, next_instr); /* unicode_concatenate consumed the ref to v */ } + /* Fast path for small ints */ + else if (PyLong_CheckExact(left) && Py_ABS(Py_SIZE(left)) <= 1 && + PyLong_CheckExact(right) && Py_ABS(Py_SIZE(right)) <= 1) { + long a, b; + if (Py_SIZE(left) != 0) { + a = ((PyLongObject*)left)->ob_digit[0]; + a *= Py_SIZE(left); + } + else + a = 0; + if (Py_SIZE(right) != 0) { + b = ((PyLongObject*)right)->ob_digit[0]; + b *= Py_SIZE(right); + } + else + b = 0; + sum = PyLong_FromLong(a + b); + Py_DECREF(left); + } else { sum = PyNumber_Add(left, right); Py_DECREF(left); @@ -1587,7 +1606,27 @@ TARGET(BINARY_SUBSCR) { PyObject *sub = POP(); PyObject *container = TOP(); - PyObject *res = PyObject_GetItem(container, sub); + PyObject *res; + /* Fast path for small positive ints */ + if (PyLong_CheckExact(sub) && + Py_SIZE(sub) <= 1 && Py_SIZE(sub) >= 0 && + PyList_CheckExact(container)) { + Py_ssize_t index; + if (Py_SIZE(sub) != 0) { + index = ((PyLongObject*)sub)->ob_digit[0]; + } + else + index = 0; + if (index < Py_SIZE(container)) { + res = PyList_GET_ITEM(container, index); + Py_INCREF(res); + } + else + goto slow_get; + } + else + slow_get: + res = PyObject_GetItem(container, sub); Py_DECREF(container); Py_DECREF(sub); SET_TOP(res);