[pypy-commit] pypy cpyext-fast-typecheck: implement PySlice_Check as a fast macro instead of going through the slow roundtrip
antocuni
pypy.commits at gmail.com
Tue Mar 20 10:38:58 EDT 2018
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: cpyext-fast-typecheck
Changeset: r94032:4744cec39496
Date: 2018-03-20 15:31 +0100
http://bitbucket.org/pypy/pypy/changeset/4744cec39496/
Log: implement PySlice_Check as a fast macro instead of going through the
slow roundtrip
diff --git a/pypy/module/cpyext/include/sliceobject.h b/pypy/module/cpyext/include/sliceobject.h
--- a/pypy/module/cpyext/include/sliceobject.h
+++ b/pypy/module/cpyext/include/sliceobject.h
@@ -17,6 +17,8 @@
PyObject *step;
} PySliceObject;
+#define PySlice_Check(op) ((op)->ob_type == &PySlice_Type)
+
#ifdef __cplusplus
}
#endif
diff --git a/pypy/module/cpyext/sliceobject.py b/pypy/module/cpyext/sliceobject.py
--- a/pypy/module/cpyext/sliceobject.py
+++ b/pypy/module/cpyext/sliceobject.py
@@ -47,7 +47,6 @@
from pypy.module.cpyext.object import _dealloc
_dealloc(space, py_obj)
-PySlice_Check, PySlice_CheckExact = build_type_checkers("Slice")
@cpython_api([PyObject, PyObject, PyObject], PyObject)
def PySlice_New(space, w_start, w_stop, w_step):
diff --git a/pypy/module/cpyext/test/test_sliceobject.py b/pypy/module/cpyext/test/test_sliceobject.py
--- a/pypy/module/cpyext/test/test_sliceobject.py
+++ b/pypy/module/cpyext/test/test_sliceobject.py
@@ -2,14 +2,8 @@
from pypy.module.cpyext.test.test_api import BaseApiTest
from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
from pypy.module.cpyext.api import Py_ssize_t, Py_ssize_tP
-from pypy.module.cpyext.sliceobject import PySlice_Check
class TestSliceObject(BaseApiTest):
- def test_slice(self, space):
- w_i = space.wrap(10)
- w_slice = space.newslice(w_i, w_i, w_i)
- assert PySlice_Check(space, w_slice)
- assert not PySlice_Check(space, w_i)
def test_GetIndicesEx(self, space, api):
w = space.wrap
More information about the pypy-commit
mailing list