From: Stefan Behnel Date: Sat, 16 Mar 2013 17:29:32 +0000 (+0100) Subject: avoid code duplication by generating List/Tuple_GetSlice utility code from a common... X-Git-Tag: 0.19b1~40 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fc1935311bf97f359df8709bee3a8620702e4cc5;p=platform%2Fupstream%2Fpython-cython.git avoid code duplication by generating List/Tuple_GetSlice utility code from a common template --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index a196160..0e871bc 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -3688,11 +3688,11 @@ class SliceIndexNode(ExprNode): else: if self.base.type is list_type: code.globalstate.use_utility_code( - UtilityCode.load_cached("SliceTupleAndList", "ObjectHandling.c")) + TempitaUtilityCode.load_cached("SliceTupleAndList", "ObjectHandling.c")) cfunc = '__Pyx_PyList_GetSlice' elif self.base.type is tuple_type: code.globalstate.use_utility_code( - UtilityCode.load_cached("SliceTupleAndList", "ObjectHandling.c")) + TempitaUtilityCode.load_cached("SliceTupleAndList", "ObjectHandling.c")) cfunc = '__Pyx_PyTuple_GetSlice' else: cfunc = '__Pyx_PySequence_GetSlice' diff --git a/Cython/Utility/ObjectHandling.c b/Cython/Utility/ObjectHandling.c index af7242f..2fc0c2d 100644 --- a/Cython/Utility/ObjectHandling.c +++ b/Cython/Utility/ObjectHandling.c @@ -625,41 +625,25 @@ static CYTHON_INLINE void __Pyx_copy_object_array(PyObject** src, PyObject** des } } -static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice( +{{for type in ['List', 'Tuple']}} +static CYTHON_INLINE PyObject* __Pyx_Py{{type}}_GetSlice( PyObject* src, Py_ssize_t start, Py_ssize_t stop) { PyObject* dest; - Py_ssize_t length = PyList_GET_SIZE(src); + Py_ssize_t length = Py{{type}}_GET_SIZE(src); __Pyx_crop_slice(&start, &stop, &length); if (unlikely(length <= 0)) - return PyList_New(0); + return Py{{type}}_New(0); - dest = PyList_New(length); + dest = Py{{type}}_New(length); if (unlikely(!dest)) return NULL; __Pyx_copy_object_array( - ((PyListObject*)src)->ob_item + start, - ((PyListObject*)dest)->ob_item, - length); - return dest; -} - -static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice( - PyObject* src, Py_ssize_t start, Py_ssize_t stop) { - PyObject* dest; - Py_ssize_t length = PyTuple_GET_SIZE(src); - __Pyx_crop_slice(&start, &stop, &length); - if (unlikely(length <= 0)) - return PyTuple_New(0); - - dest = PyTuple_New(length); - if (unlikely(!dest)) - return NULL; - __Pyx_copy_object_array( - ((PyTupleObject*)src)->ob_item + start, - ((PyTupleObject*)dest)->ob_item, + ((Py{{type}}Object*)src)->ob_item + start, + ((Py{{type}}Object*)dest)->ob_item, length); return dest; } +{{endfor}} #endif /////////////// FindPy2Metaclass.proto ///////////////