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
6002b1e0
Commit
6002b1e0
authored
Mar 29, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
speed up equality comparisons with constant Python integer/float values
parent
8af9ce41
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
139 additions
and
52 deletions
+139
-52
CHANGES.rst
CHANGES.rst
+2
-1
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+13
-1
Cython/Utility/Optimize.c
Cython/Utility/Optimize.c
+124
-50
No files found.
CHANGES.rst
View file @
6002b1e0
...
...
@@ -17,7 +17,8 @@ Features added
* Optimisations for PyLong are enabled in Py2.7 (not only Py3.x).
* Adding/subtracting/dividing constant Python floats and small integers is faster.
* Adding/subtracting/dividing and equality comparisons with constant Python
floats and small integers are faster.
* Binary and/or/xor/rshift operations and division/modulus with small
constant Python integers are faster.
...
...
Cython/Compiler/Optimize.py
View file @
6002b1e0
...
...
@@ -2802,6 +2802,12 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
def
_handle_simple_method_object___sub__
(
self
,
node
,
function
,
args
,
is_unbound_method
):
return
self
.
_optimise_num_binop
(
'Subtract'
,
node
,
function
,
args
,
is_unbound_method
)
def
_handle_simple_method_object___eq__
(
self
,
node
,
function
,
args
,
is_unbound_method
):
return
self
.
_optimise_num_binop
(
'Eq'
,
node
,
function
,
args
,
is_unbound_method
)
def
_handle_simple_method_object___neq__
(
self
,
node
,
function
,
args
,
is_unbound_method
):
return
self
.
_optimise_num_binop
(
'Ne'
,
node
,
function
,
args
,
is_unbound_method
)
def
_handle_simple_method_object___and__
(
self
,
node
,
function
,
args
,
is_unbound_method
):
return
self
.
_optimise_num_binop
(
'And'
,
node
,
function
,
args
,
is_unbound_method
)
...
...
@@ -2859,6 +2865,12 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
def
_handle_simple_method_float___div__
(
self
,
node
,
function
,
args
,
is_unbound_method
):
return
self
.
_optimise_num_binop
(
'Divide'
,
node
,
function
,
args
,
is_unbound_method
)
def
_handle_simple_method_float___eq__
(
self
,
node
,
function
,
args
,
is_unbound_method
):
return
self
.
_optimise_num_binop
(
'Eq'
,
node
,
function
,
args
,
is_unbound_method
)
def
_handle_simple_method_float___neq__
(
self
,
node
,
function
,
args
,
is_unbound_method
):
return
self
.
_optimise_num_binop
(
'Ne'
,
node
,
function
,
args
,
is_unbound_method
)
def
_optimise_num_binop
(
self
,
operator
,
node
,
function
,
args
,
is_unbound_method
):
"""
Optimise math operators for (likely) float or small integer operations.
...
...
@@ -2889,7 +2901,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
is_float
=
isinstance
(
numval
,
ExprNodes
.
FloatNode
)
if
is_float
:
if
operator
not
in
(
'Add'
,
'Subtract'
,
'TrueDivide'
,
'Divide'
):
if
operator
not
in
(
'Add'
,
'Subtract'
,
'TrueDivide'
,
'Divide'
,
'Eq'
,
'Ne'
):
return
node
elif
operator
==
'Divide'
:
# mixed old-/new-style division is not currently optimised for integers
...
...
Cython/Utility/Optimize.c
View file @
6002b1e0
This diff is collapsed.
Click to expand it.
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