Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
4c5cc91b
Commit
4c5cc91b
authored
Aug 23, 2019
by
Jeroen Demeyer
Committed by
Stefan Behnel
Aug 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor SliceTupleAndList utility code (GH-3087)
parent
de176c65
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
21 deletions
+51
-21
Cython/Utility/ObjectHandling.c
Cython/Utility/ObjectHandling.c
+51
-21
No files found.
Cython/Utility/ObjectHandling.c
View file @
4c5cc91b
...
...
@@ -735,6 +735,55 @@ bad:
}
/////////////// TupleAndListFromArray.proto ///////////////
#if CYTHON_COMPILING_IN_CPYTHON
static
CYTHON_INLINE
PyObject
*
__Pyx_PyTuple_FromArray
(
PyObject
*
const
*
src
,
Py_ssize_t
n
);
static
CYTHON_INLINE
PyObject
*
__Pyx_PyList_FromArray
(
PyObject
*
const
*
src
,
Py_ssize_t
n
);
#endif
/////////////// TupleAndListFromArray ///////////////
//@substitute: naming
#if CYTHON_COMPILING_IN_CPYTHON
static
CYTHON_INLINE
void
__Pyx_copy_object_array
(
PyObject
*
const
*
CYTHON_RESTRICT
src
,
PyObject
**
CYTHON_RESTRICT
dest
,
Py_ssize_t
length
)
{
PyObject
*
v
;
Py_ssize_t
i
;
for
(
i
=
0
;
i
<
length
;
i
++
)
{
v
=
dest
[
i
]
=
src
[
i
];
Py_INCREF
(
v
);
}
}
static
CYTHON_INLINE
PyObject
*
__Pyx_PyTuple_FromArray
(
PyObject
*
const
*
src
,
Py_ssize_t
n
)
{
PyObject
*
res
;
if
(
n
<=
0
)
{
Py_INCREF
(
$
empty_tuple
);
return
$
empty_tuple
;
}
res
=
PyTuple_New
(
n
);
if
(
unlikely
(
res
==
NULL
))
return
NULL
;
__Pyx_copy_object_array
(
src
,
((
PyTupleObject
*
)
res
)
->
ob_item
,
n
);
return
res
;
}
static
CYTHON_INLINE
PyObject
*
__Pyx_PyList_FromArray
(
PyObject
*
const
*
src
,
Py_ssize_t
n
)
{
PyObject
*
res
;
if
(
n
<=
0
)
{
return
PyList_New
(
0
);
}
res
=
PyList_New
(
n
);
if
(
unlikely
(
res
==
NULL
))
return
NULL
;
__Pyx_copy_object_array
(
src
,
((
PyListObject
*
)
res
)
->
ob_item
,
n
);
return
res
;
}
#endif
/////////////// SliceTupleAndList.proto ///////////////
#if CYTHON_COMPILING_IN_CPYTHON
...
...
@@ -746,6 +795,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(PyObject* src, Py_ssize_t
#endif
/////////////// SliceTupleAndList ///////////////
//@requires: TupleAndListFromArray
#if CYTHON_COMPILING_IN_CPYTHON
static
CYTHON_INLINE
void
__Pyx_crop_slice
(
Py_ssize_t
*
_start
,
Py_ssize_t
*
_stop
,
Py_ssize_t
*
_length
)
{
...
...
@@ -766,32 +816,12 @@ static CYTHON_INLINE void __Pyx_crop_slice(Py_ssize_t* _start, Py_ssize_t* _stop
*
_stop
=
stop
;
}
static
CYTHON_INLINE
void
__Pyx_copy_object_array
(
PyObject
**
CYTHON_RESTRICT
src
,
PyObject
**
CYTHON_RESTRICT
dest
,
Py_ssize_t
length
)
{
PyObject
*
v
;
Py_ssize_t
i
;
for
(
i
=
0
;
i
<
length
;
i
++
)
{
v
=
dest
[
i
]
=
src
[
i
];
Py_INCREF
(
v
);
}
}
{{
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
=
Py
{{
type
}}
_GET_SIZE
(
src
);
__Pyx_crop_slice
(
&
start
,
&
stop
,
&
length
);
if
(
unlikely
(
length
<=
0
))
return
Py
{{
type
}}
_New
(
0
);
dest
=
Py
{{
type
}}
_New
(
length
);
if
(
unlikely
(
!
dest
))
return
NULL
;
__Pyx_copy_object_array
(
((
Py
{{
type
}}
Object
*
)
src
)
->
ob_item
+
start
,
((
Py
{{
type
}}
Object
*
)
dest
)
->
ob_item
,
length
);
return
dest
;
return
__Pyx_Py
{{
type
}}
_FromArray
(((
Py
{{
type
}}
Object
*
)
src
)
->
ob_item
+
start
,
length
);
}
{{
endfor
}}
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment