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
Gwenaël Samain
cython
Commits
3575912c
Commit
3575912c
authored
Jul 01, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extracted GetItemInt utility code into ObjectHandling.c utility file
parent
78bf7d66
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
81 deletions
+76
-81
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+2
-81
Cython/Utility/ObjectHandling.c
Cython/Utility/ObjectHandling.c
+74
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
3575912c
...
@@ -2962,7 +2962,8 @@ class IndexNode(ExprNode):
...
@@ -2962,7 +2962,8 @@ class IndexNode(ExprNode):
function
=
"__Pyx_GetItemInt_Tuple"
function
=
"__Pyx_GetItemInt_Tuple"
else
:
else
:
function
=
"__Pyx_GetItemInt"
function
=
"__Pyx_GetItemInt"
code
.
globalstate
.
use_utility_code
(
getitem_int_utility_code
)
code
.
globalstate
.
use_utility_code
(
TempitaUtilityCode
.
load_cached
(
"GetItemInt"
,
"ObjectHandling.c"
))
else
:
else
:
index_code
=
self
.
index
.
py_result
()
index_code
=
self
.
index
.
py_result
()
if
self
.
base
.
type
is
dict_type
:
if
self
.
base
.
type
is
dict_type
:
...
@@ -9903,86 +9904,6 @@ static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Generic(PyObject* ustring,
...
@@ -9903,86 +9904,6 @@ static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Generic(PyObject* ustring,
}
}
'''
)
'''
)
getitem_int_utility_code
=
UtilityCode
(
proto
=
"""
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
PyObject *r;
if (!j) return NULL;
r = PyObject_GetItem(o, j);
Py_DECREF(j);
return r;
}
"""
+
''
.
join
([
"""
#define __Pyx_GetItemInt_%(type)s(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ?
\
\
__Pyx_GetItemInt_%(type)s_Fast(o, i) :
\
\
__Pyx_GetItemInt_Generic(o, to_py_func(i)))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_%(type)s_Fast(PyObject *o, Py_ssize_t i) {
#if CYTHON_COMPILING_IN_CPYTHON
if (likely((0 <= i) & (i < Py%(type)s_GET_SIZE(o)))) {
PyObject *r = Py%(type)s_GET_ITEM(o, i);
Py_INCREF(r);
return r;
}
else if ((-Py%(type)s_GET_SIZE(o) <= i) & (i < 0)) {
PyObject *r = Py%(type)s_GET_ITEM(o, Py%(type)s_GET_SIZE(o) + i);
Py_INCREF(r);
return r;
}
return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
return PySequence_GetItem(o, i);
#endif
}
"""
%
{
'type'
:
type_name
}
for
type_name
in
(
'List'
,
'Tuple'
)
])
+
"""
#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ?
\
\
__Pyx_GetItemInt_Fast(o, i) :
\
\
__Pyx_GetItemInt_Generic(o, to_py_func(i)))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) {
#if CYTHON_COMPILING_IN_CPYTHON
if (PyList_CheckExact(o)) {
Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) {
PyObject *r = PyList_GET_ITEM(o, n);
Py_INCREF(r);
return r;
}
}
else if (PyTuple_CheckExact(o)) {
Py_ssize_t n = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
PyObject *r = PyTuple_GET_ITEM(o, n);
Py_INCREF(r);
return r;
}
} else { /* inlined PySequence_GetItem() */
PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
if (likely(m && m->sq_item)) {
if (unlikely(i < 0) && likely(m->sq_length)) {
Py_ssize_t l = m->sq_length(o);
if (unlikely(l < 0)) return NULL;
i += l;
}
return m->sq_item(o, i);
}
}
#else
if (PySequence_Check(o)) {
return PySequence_GetItem(o, i);
}
#endif
return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}
"""
)
#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------
raise_too_many_values_to_unpack
=
UtilityCode
.
load_cached
(
"RaiseTooManyValuesToUnpack"
,
"ObjectHandling.c"
)
raise_too_many_values_to_unpack
=
UtilityCode
.
load_cached
(
"RaiseTooManyValuesToUnpack"
,
"ObjectHandling.c"
)
...
...
Cython/Utility/ObjectHandling.c
View file @
3575912c
...
@@ -232,6 +232,80 @@ static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
...
@@ -232,6 +232,80 @@ static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
#endif
#endif
/////////////// GetItemInt.proto ///////////////
static
CYTHON_INLINE
PyObject
*
__Pyx_GetItemInt_Generic
(
PyObject
*
o
,
PyObject
*
j
)
{
PyObject
*
r
;
if
(
!
j
)
return
NULL
;
r
=
PyObject_GetItem
(
o
,
j
);
Py_DECREF
(
j
);
return
r
;
}
{{
for
type
in
[
'
List
'
,
'
Tuple
'
]}}
#define __Pyx_GetItemInt_{{type}}(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
__Pyx_GetItemInt_{{type}}_Fast(o, i) : \
__Pyx_GetItemInt_Generic(o, to_py_func(i)))
static
CYTHON_INLINE
PyObject
*
__Pyx_GetItemInt_
{{
type
}}
_Fast
(
PyObject
*
o
,
Py_ssize_t
i
)
{
#if CYTHON_COMPILING_IN_CPYTHON
if
(
likely
((
0
<=
i
)
&
(
i
<
Py
{{
type
}}
_GET_SIZE
(
o
))))
{
PyObject
*
r
=
Py
{{
type
}}
_GET_ITEM
(
o
,
i
);
Py_INCREF
(
r
);
return
r
;
}
else
if
((
-
Py
{{
type
}}
_GET_SIZE
(
o
)
<=
i
)
&
(
i
<
0
))
{
PyObject
*
r
=
Py
{{
type
}}
_GET_ITEM
(
o
,
Py
{{
type
}}
_GET_SIZE
(
o
)
+
i
);
Py_INCREF
(
r
);
return
r
;
}
return
__Pyx_GetItemInt_Generic
(
o
,
PyInt_FromSsize_t
(
i
));
#else
return
PySequence_GetItem
(
o
,
i
);
#endif
}
{{
endfor
}}
#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
__Pyx_GetItemInt_Fast(o, i) : \
__Pyx_GetItemInt_Generic(o, to_py_func(i)))
static
CYTHON_INLINE
PyObject
*
__Pyx_GetItemInt_Fast
(
PyObject
*
o
,
Py_ssize_t
i
)
{
#if CYTHON_COMPILING_IN_CPYTHON
if
(
PyList_CheckExact
(
o
))
{
Py_ssize_t
n
=
(
likely
(
i
>=
0
))
?
i
:
i
+
PyList_GET_SIZE
(
o
);
if
(
likely
((
n
>=
0
)
&
(
n
<
PyList_GET_SIZE
(
o
))))
{
PyObject
*
r
=
PyList_GET_ITEM
(
o
,
n
);
Py_INCREF
(
r
);
return
r
;
}
}
else
if
(
PyTuple_CheckExact
(
o
))
{
Py_ssize_t
n
=
(
likely
(
i
>=
0
))
?
i
:
i
+
PyTuple_GET_SIZE
(
o
);
if
(
likely
((
n
>=
0
)
&
(
n
<
PyTuple_GET_SIZE
(
o
))))
{
PyObject
*
r
=
PyTuple_GET_ITEM
(
o
,
n
);
Py_INCREF
(
r
);
return
r
;
}
}
else
{
/* inlined PySequence_GetItem() */
PySequenceMethods
*
m
=
Py_TYPE
(
o
)
->
tp_as_sequence
;
if
(
likely
(
m
&&
m
->
sq_item
))
{
if
(
unlikely
(
i
<
0
)
&&
likely
(
m
->
sq_length
))
{
Py_ssize_t
l
=
m
->
sq_length
(
o
);
if
(
unlikely
(
l
<
0
))
return
NULL
;
i
+=
l
;
}
return
m
->
sq_item
(
o
,
i
);
}
}
#else
if
(
PySequence_Check
(
o
))
{
return
PySequence_GetItem
(
o
,
i
);
}
#endif
return
__Pyx_GetItemInt_Generic
(
o
,
PyInt_FromSsize_t
(
i
));
}
/////////////// SetItemInt.proto ///////////////
/////////////// SetItemInt.proto ///////////////
#define __Pyx_SetItemInt(o, i, v, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
#define __Pyx_SetItemInt(o, i, v, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
...
...
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