Commit fd7b1751 authored by Stefan Behnel's avatar Stefan Behnel

optimise object.pop() for sets

--HG--
extra : rebase_source : a4c51d10f4b7c88a994a0687202ac032a7baff33
parent b04e040d
...@@ -3098,7 +3098,6 @@ impl = "" ...@@ -3098,7 +3098,6 @@ impl = ""
pop_utility_code = UtilityCode( pop_utility_code = UtilityCode(
proto = """ proto = """
static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L) { static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L) {
PyObject *r, *m;
#if PY_VERSION_HEX >= 0x02040000 #if PY_VERSION_HEX >= 0x02040000
if (likely(PyList_CheckExact(L)) if (likely(PyList_CheckExact(L))
/* Check that both the size is positive and no reallocation shrinking needs to be done. */ /* Check that both the size is positive and no reallocation shrinking needs to be done. */
...@@ -3106,12 +3105,11 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L) { ...@@ -3106,12 +3105,11 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L) {
Py_SIZE(L) -= 1; Py_SIZE(L) -= 1;
return PyList_GET_ITEM(L, PyList_GET_SIZE(L)); return PyList_GET_ITEM(L, PyList_GET_SIZE(L));
} }
else if (Py_TYPE(L) == (&PySet_Type)) {
return PySet_Pop(L);
}
#endif #endif
m = __Pyx_GetAttrString(L, "pop"); return PyObject_CallMethod(L, (char*)"pop", NULL);
if (!m) return NULL;
r = PyObject_CallObject(m, NULL);
Py_DECREF(m);
return r;
} }
""", """,
impl = "" impl = ""
......
...@@ -89,6 +89,17 @@ def test_set_pop(): ...@@ -89,6 +89,17 @@ def test_set_pop():
two = s1.pop() two = s1.pop()
return s1 return s1
@cython.test_fail_if_path_exists("//SimpleCallNode//NameNode")
def test_object_pop(s):
"""
>>> s = _set([2])
>>> test_object_pop(s)
2
>>> list(s)
[]
"""
return s.pop()
def test_set_discard(): def test_set_discard():
""" """
>>> type(test_set_discard()) is _set >>> type(test_set_discard()) is _set
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment