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
2fa0e9f6
Commit
2fa0e9f6
authored
Mar 25, 2018
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inline fast special cases for "abs(PyLong)" when the argument is non-negative or small.
parent
e4e2be30
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
1 deletion
+34
-1
CHANGES.rst
CHANGES.rst
+5
-0
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+2
-1
Cython/Utility/Builtins.c
Cython/Utility/Builtins.c
+27
-0
No files found.
CHANGES.rst
View file @
2fa0e9f6
...
...
@@ -5,6 +5,11 @@ Cython Changelog
0.28.2 (2018-??-??)
===================
Features added
--------------
* ``abs()`` is faster for Python long objects.
Bugs fixed
----------
...
...
Cython/Compiler/Builtin.py
View file @
2fa0e9f6
...
...
@@ -124,7 +124,8 @@ builtin_function_table = [
PyrexTypes
.
c_double_complex_type
,
PyrexTypes
.
c_longdouble_complex_type
)
)
+
[
BuiltinFunction
(
'abs'
,
"O"
,
"O"
,
"PyNumber_Absolute"
),
BuiltinFunction
(
'abs'
,
"O"
,
"O"
,
"__Pyx_PyNumber_Absolute"
,
utility_code
=
UtilityCode
.
load
(
"py_abs"
,
"Builtins.c"
)),
#('all', "", "", ""),
#('any', "", "", ""),
#('ascii', "", "", ""),
...
...
Cython/Utility/Builtins.c
View file @
2fa0e9f6
...
...
@@ -253,6 +253,33 @@ static CYTHON_INLINE PY_LONG_LONG __Pyx_abs_longlong(PY_LONG_LONG x) {
}
//////////////////// py_abs.proto ////////////////////
#if CYTHON_USE_PYLONG_INTERNALS
static
PyObject
*
__Pyx_PyLong_AbsNeg
(
PyObject
*
num
);
/*proto*/
#define __Pyx_PyNumber_Absolute(x) \
((likely(PyLong_CheckExact(x))) ? \
(likely(Py_SIZE(x) >= 0) ? (Py_INCREF(x), (x)) : __Pyx_PyLong_AbsNeg(x)) : \
PyNumber_Absolute(x))
#else
#define __Pyx_PyNumber_Absolute(x) PyNumber_Absolute(x)
#endif
//////////////////// py_abs ////////////////////
#if CYTHON_USE_PYLONG_INTERNALS
static
PyObject
*
__Pyx_PyLong_AbsNeg
(
PyObject
*
n
)
{
if
(
likely
(
Py_SIZE
(
n
)
==
-
1
))
{
// digits are unsigned
return
PyLong_FromLong
(((
PyLongObject
*
)
n
)
->
ob_digit
[
0
]);
}
return
((
PyTypeObject
*
)
Py_TYPE
(
n
))
->
tp_as_number
->
nb_negative
(
n
);
}
#endif
//////////////////// pow2.proto ////////////////////
#define __Pyx_PyNumber_Power2(a, b) PyNumber_Power(a, b, Py_None)
...
...
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