Fix pop optimization for 2.3.
authorRobert Bradshaw <robertwb@math.washington.edu>
Wed, 17 Feb 2010 09:05:21 +0000 (01:05 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Wed, 17 Feb 2010 09:05:21 +0000 (01:05 -0800)
Cython/Compiler/Optimize.py

index b836090b2074eccd7e309f88868096c4c7875b8d..3a01316d3aea8dba7cfd1d7ed8c4b6185d0a6075 100644 (file)
@@ -1621,20 +1621,20 @@ impl = ""
 pop_utility_code = UtilityCode(
 proto = """
 static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L) {
+#if PY_VERSION_HEX >= 0x02040000
     if (likely(PyList_CheckExact(L))
             /* Check that both the size is positive and no reallocation shrinking needs to be done. */
             && likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) {
         Py_SIZE(L) -= 1;
         return PyList_GET_ITEM(L, PyList_GET_SIZE(L));
     }
-    else {
-        PyObject *r, *m;
-        m = __Pyx_GetAttrString(L, "pop");
-        if (!m) return NULL;
-        r = PyObject_CallObject(m, NULL);
-        Py_DECREF(m);
-        return r;
-    }
+#endif
+    PyObject *r, *m;
+    m = __Pyx_GetAttrString(L, "pop");
+    if (!m) return NULL;
+    r = PyObject_CallObject(m, NULL);
+    Py_DECREF(m);
+    return r;
 }
 """,
 impl = ""
@@ -1647,6 +1647,7 @@ static PyObject* __Pyx_PyObject_PopIndex(PyObject* L, Py_ssize_t ix);
 impl = """
 static PyObject* __Pyx_PyObject_PopIndex(PyObject* L, Py_ssize_t ix) {
     PyObject *r, *m, *t, *py_ix;
+#if PY_VERSION_HEX >= 0x02040000
     if (likely(PyList_CheckExact(L))) {
         Py_ssize_t size = PyList_GET_SIZE(L);
         if (likely(size > (((PyListObject*)L)->allocated >> 1))) {
@@ -1665,6 +1666,7 @@ static PyObject* __Pyx_PyObject_PopIndex(PyObject* L, Py_ssize_t ix) {
             }
         }
     }
+#endif
     py_ix = t = NULL;
     m = __Pyx_GetAttrString(L, "pop");
     if (!m) goto bad;