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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
76f3852e
Commit
76f3852e
authored
Jul 10, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix conflict between genexpr inlining and dict iteration optimisations
parent
c1d71d70
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
6 deletions
+28
-6
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+6
-6
tests/run/unicodemethods.pyx
tests/run/unicodemethods.pyx
+22
-0
No files found.
Cython/Compiler/Optimize.py
View file @
76f3852e
...
@@ -1574,7 +1574,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
...
@@ -1574,7 +1574,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
node
.
pos
,
node
.
pos
,
value
=
ExprNodes
.
BoolNode
(
yield_expression
.
pos
,
value
=
not
is_any
,
constant_result
=
not
is_any
))
value
=
ExprNodes
.
BoolNode
(
yield_expression
.
pos
,
value
=
not
is_any
,
constant_result
=
not
is_any
))
Visitor
.
recursively_replace_node
(
loop
_node
,
yield_stat_node
,
test_node
)
Visitor
.
recursively_replace_node
(
gen_expr
_node
,
yield_stat_node
,
test_node
)
return
ExprNodes
.
InlinedGeneratorExpressionNode
(
return
ExprNodes
.
InlinedGeneratorExpressionNode
(
gen_expr_node
.
pos
,
gen
=
gen_expr_node
,
orig_func
=
'any'
if
is_any
else
'all'
)
gen_expr_node
.
pos
,
gen
=
gen_expr_node
,
orig_func
=
'any'
if
is_any
else
'all'
)
...
@@ -1614,7 +1614,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
...
@@ -1614,7 +1614,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
expr
=
yield_expression
,
expr
=
yield_expression
,
target
=
list_node
.
target
)
target
=
list_node
.
target
)
Visitor
.
recursively_replace_node
(
loop
_node
,
yield_stat_node
,
append_node
)
Visitor
.
recursively_replace_node
(
gen_expr
_node
,
yield_stat_node
,
append_node
)
elif
arg
.
is_sequence_constructor
:
elif
arg
.
is_sequence_constructor
:
# sorted([a, b, c]) or sorted((a, b, c)). The result is always a list,
# sorted([a, b, c]) or sorted((a, b, c)). The result is always a list,
...
@@ -1687,7 +1687,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
...
@@ -1687,7 +1687,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
rhs
=
ExprNodes
.
binop_node
(
node
.
pos
,
'+'
,
result_ref
,
yield_expression
)
rhs
=
ExprNodes
.
binop_node
(
node
.
pos
,
'+'
,
result_ref
,
yield_expression
)
)
)
Visitor
.
recursively_replace_node
(
loop
_node
,
yield_stat_node
,
add_node
)
Visitor
.
recursively_replace_node
(
gen_expr
_node
,
yield_stat_node
,
add_node
)
exec_code
=
Nodes
.
StatListNode
(
exec_code
=
Nodes
.
StatListNode
(
node
.
pos
,
node
.
pos
,
...
@@ -1806,7 +1806,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
...
@@ -1806,7 +1806,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
expr
=
yield_expression
,
expr
=
yield_expression
,
target
=
result_node
.
target
)
target
=
result_node
.
target
)
Visitor
.
recursively_replace_node
(
loop
_node
,
yield_stat_node
,
append_node
)
Visitor
.
recursively_replace_node
(
gen_expr
_node
,
yield_stat_node
,
append_node
)
return
result_node
return
result_node
def
_handle_simple_function_dict
(
self
,
node
,
pos_args
):
def
_handle_simple_function_dict
(
self
,
node
,
pos_args
):
...
@@ -1840,7 +1840,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
...
@@ -1840,7 +1840,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
value_expr
=
yield_expression
.
args
[
1
],
value_expr
=
yield_expression
.
args
[
1
],
target
=
result_node
.
target
)
target
=
result_node
.
target
)
Visitor
.
recursively_replace_node
(
loop
_node
,
yield_stat_node
,
append_node
)
Visitor
.
recursively_replace_node
(
gen_expr
_node
,
yield_stat_node
,
append_node
)
return
result_node
return
result_node
# specific handlers for general call nodes
# specific handlers for general call nodes
...
@@ -3107,7 +3107,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
...
@@ -3107,7 +3107,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
expr
=
yield_expression
,
expr
=
yield_expression
,
target
=
inlined_genexpr
.
target
)
target
=
inlined_genexpr
.
target
)
Visitor
.
recursively_replace_node
(
loop
_node
,
yield_stat_node
,
append_node
)
Visitor
.
recursively_replace_node
(
gen_expr
_node
,
yield_stat_node
,
append_node
)
args
[
1
]
=
inlined_genexpr
args
[
1
]
=
inlined_genexpr
return
self
.
_substitute_method_call
(
return
self
.
_substitute_method_call
(
...
...
tests/run/unicodemethods.pyx
View file @
76f3852e
...
@@ -247,6 +247,28 @@ def join_sep_genexpr(l):
...
@@ -247,6 +247,28 @@ def join_sep_genexpr(l):
return
result
return
result
@
cython
.
test_fail_if_path_exists
(
"//CoerceToPyTypeNode"
,
"//CoerceFromPyTypeNode"
,
"//CastNode"
,
"//TypecastNode"
,
)
@
cython
.
test_assert_path_exists
(
"//PythonCapiCallNode"
,
"//InlinedGeneratorExpressionNode"
)
def
join_sep_genexpr_dictiter
(
dict
d
):
"""
>>> l = text.split()
>>> d = dict(zip(range(len(l)), l))
>>> print('|'.join( sorted(' '.join('%s:%s' % (k, v) for k, v in d.items()).split()) ))
0:ab|1:jd|2:sdflk|3:as|4:sa|5:sadas|6:asdas|7:fsdf
>>> print('|'.join( sorted(join_sep_genexpr_dictiter(d).split())) )
0:ab|1:jd|2:sdflk|3:as|4:sa|5:sadas|6:asdas|7:fsdf
"""
result
=
u' '
.
join
(
'%s:%s'
%
(
k
,
v
)
for
k
,
v
in
d
.
iteritems
())
assert
cython
.
typeof
(
result
)
==
'unicode object'
,
cython
.
typeof
(
result
)
return
result
@
cython
.
test_assert_path_exists
(
@
cython
.
test_assert_path_exists
(
"//PythonCapiCallNode"
,
"//PythonCapiCallNode"
,
)
)
...
...
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