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
Boxiang Sun
cython
Commits
82afcb57
Commit
82afcb57
authored
Nov 30, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimise sum([int_const for ...]) into an inlined sum(genexpr)
parent
8caa6c6a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
5 deletions
+18
-5
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+18
-5
No files found.
Cython/Compiler/Optimize.py
View file @
82afcb57
...
@@ -1339,14 +1339,26 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
...
@@ -1339,14 +1339,26 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
"""
"""
if
len
(
pos_args
)
not
in
(
1
,
2
):
if
len
(
pos_args
)
not
in
(
1
,
2
):
return
node
return
node
if
not
isinstance
(
pos_args
[
0
],
ExprNodes
.
GeneratorExpressionNode
):
if
not
isinstance
(
pos_args
[
0
],
(
ExprNodes
.
GeneratorExpressionNode
,
ExprNodes
.
ComprehensionNode
)):
return
node
return
node
gen_expr_node
=
pos_args
[
0
]
gen_expr_node
=
pos_args
[
0
]
loop_node
=
gen_expr_node
.
loop
loop_node
=
gen_expr_node
.
loop
if
isinstance
(
gen_expr_node
,
ExprNodes
.
GeneratorExpressionNode
):
yield_expression
,
yield_stat_node
=
self
.
_find_single_yield_expression
(
loop_node
)
yield_expression
,
yield_stat_node
=
self
.
_find_single_yield_expression
(
loop_node
)
if
yield_expression
is
None
:
if
yield_expression
is
None
:
return
node
return
node
else
:
# ComprehensionNode
yield_stat_node
=
gen_expr_node
.
append
yield_expression
=
yield_stat_node
.
expr
try
:
if
not
yield_expression
.
is_literal
or
not
yield_expression
.
type
.
is_int
:
return
node
except
AttributeError
:
return
node
# in case we don't have a type yet
# special case: old Py2 backwards compatible "sum([int_const for ...])"
# can safely be unpacked into a genexpr
if
len
(
pos_args
)
==
1
:
if
len
(
pos_args
)
==
1
:
start
=
ExprNodes
.
IntNode
(
node
.
pos
,
value
=
'0'
,
constant_result
=
0
)
start
=
ExprNodes
.
IntNode
(
node
.
pos
,
value
=
'0'
,
constant_result
=
0
)
...
@@ -1375,7 +1387,8 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
...
@@ -1375,7 +1387,8 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
return
ExprNodes
.
InlinedGeneratorExpressionNode
(
return
ExprNodes
.
InlinedGeneratorExpressionNode
(
gen_expr_node
.
pos
,
loop
=
exec_code
,
result_node
=
result_ref
,
gen_expr_node
.
pos
,
loop
=
exec_code
,
result_node
=
result_ref
,
expr_scope
=
gen_expr_node
.
expr_scope
,
orig_func
=
'sum'
)
expr_scope
=
gen_expr_node
.
expr_scope
,
orig_func
=
'sum'
,
has_local_scope
=
gen_expr_node
.
has_local_scope
)
def
_handle_simple_function_min
(
self
,
node
,
pos_args
):
def
_handle_simple_function_min
(
self
,
node
,
pos_args
):
return
self
.
_optimise_min_max
(
node
,
pos_args
,
'<'
)
return
self
.
_optimise_min_max
(
node
,
pos_args
,
'<'
)
...
...
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