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
14cf1dde
Commit
14cf1dde
authored
Mar 22, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimise integer type conversion also for 2-digit PyLong values
parent
2bd2a741
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
13 deletions
+24
-13
Cython/Utility/TypeConversion.c
Cython/Utility/TypeConversion.c
+24
-13
No files found.
Cython/Utility/TypeConversion.c
View file @
14cf1dde
...
...
@@ -288,14 +288,17 @@ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
return
PyInt_AS_LONG
(
b
);
#endif
if
(
likely
(
PyLong_CheckExact
(
b
)))
{
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
switch
(
Py_SIZE
(
b
))
{
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 && CYTHON_USE_PYLONG_INTERNALS
switch
(
Py_SIZE
(
b
))
{
case
-
1
:
return
-
(
sdigit
)((
PyLongObject
*
)
b
)
->
ob_digit
[
0
];
case
0
:
return
0
;
case
1
:
return
((
PyLongObject
*
)
b
)
->
ob_digit
[
0
];
}
#endif
case
2
:
if
(
8
*
sizeof
(
Py_ssize_t
)
>
2
*
PyLong_SHIFT
)
{
return
(
Py_ssize_t
)
((((
size_t
)((
PyLongObject
*
)
b
)
->
ob_digit
[
1
])
<<
PyLong_SHIFT
)
|
((
PyLongObject
*
)
b
)
->
ob_digit
[
0
]);
}
break
;
}
#endif
return
PyLong_AsSsize_t
(
b
);
}
...
...
@@ -548,15 +551,19 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) {
#endif
if
(
likely
(
PyLong_Check
(
x
)))
{
if
(
is_unsigned
)
{
#if CYTHON_COMPILING_IN_CPYTHON
&& PY_MAJOR_VERSION >= 3
#if
CYTHON_USE_PYLONG_INTERNALS
#if CYTHON_COMPILING_IN_CPYTHON
#if PY_MAJOR_VERSION >= 3 &&
CYTHON_USE_PYLONG_INTERNALS
switch
(
Py_SIZE
(
x
))
{
case
0
:
return
0
;
case
1
:
__PYX_VERIFY_RETURN_INT
({{
TYPE
}},
digit
,
((
PyLongObject
*
)
x
)
->
ob_digit
[
0
]);
case
2
:
if
((
8
*
sizeof
({{
TYPE
}})
>
PyLong_SHIFT
)
&&
(
8
*
sizeof
(
unsigned
long
)
>
2
*
PyLong_SHIFT
))
{
__PYX_VERIFY_RETURN_INT
({{
TYPE
}},
unsigned
long
,
(((
unsigned
long
)((
PyLongObject
*
)
x
)
->
ob_digit
[
1
])
<<
PyLong_SHIFT
)
|
((
PyLongObject
*
)
x
)
->
ob_digit
[
0
]);
}
break
;
}
#endif
#endif
#if CYTHON_COMPILING_IN_CPYTHON
#endif
if
(
unlikely
(
Py_SIZE
(
x
)
<
0
))
{
goto
raise_neg_overflow
;
}
...
...
@@ -567,14 +574,18 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) {
__PYX_VERIFY_RETURN_INT
({{
TYPE
}},
unsigned
long
long
,
PyLong_AsUnsignedLongLong
(
x
))
}
}
else
{
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 && CYTHON_USE_PYLONG_INTERNALS
switch
(
Py_SIZE
(
x
))
{
case
0
:
return
0
;
case
1
:
__PYX_VERIFY_RETURN_INT
({{
TYPE
}},
digit
,
+
(((
PyLongObject
*
)
x
)
->
ob_digit
[
0
]));
case
-
1
:
__PYX_VERIFY_RETURN_INT
({{
TYPE
}},
sdigit
,
-
(
sdigit
)
((
PyLongObject
*
)
x
)
->
ob_digit
[
0
]);
case
2
:
if
((
8
*
sizeof
({{
TYPE
}})
>
PyLong_SHIFT
)
&&
(
8
*
sizeof
(
unsigned
long
)
>
2
*
PyLong_SHIFT
))
{
__PYX_VERIFY_RETURN_INT
({{
TYPE
}},
unsigned
long
,
(((
unsigned
long
)((
PyLongObject
*
)
x
)
->
ob_digit
[
1
])
<<
PyLong_SHIFT
)
|
((
PyLongObject
*
)
x
)
->
ob_digit
[
0
]);
}
break
;
}
#endif
#endif
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
long
))
{
__PYX_VERIFY_RETURN_INT
({{
TYPE
}},
long
,
PyLong_AsLong
(
x
))
...
...
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