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
5765b020
Commit
5765b020
authored
Sep 12, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
safely replace all node references when injecting a literal set for set([...])
parent
43342ab9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
3 deletions
+21
-3
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+5
-3
tests/run/set.pyx
tests/run/set.pyx
+16
-0
No files found.
Cython/Compiler/Optimize.py
View file @
5765b020
...
...
@@ -1775,7 +1775,8 @@ class InlineDefNodeCalls(Visitor.NodeRefCleanupMixin, Visitor.EnvTransform):
return
node
class
OptimizeBuiltinCalls
(
Visitor
.
MethodDispatcherTransform
):
class
OptimizeBuiltinCalls
(
Visitor
.
NodeRefCleanupMixin
,
Visitor
.
MethodDispatcherTransform
):
"""Optimize some common methods calls and instantiation patterns
for builtin types *after* the type analysis phase.
...
...
@@ -2061,17 +2062,18 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
temps
.
append
(
arg
)
args
.
append
(
arg
)
result
=
ExprNodes
.
SetNode
(
node
.
pos
,
is_temp
=
1
,
args
=
args
)
self
.
replace
(
node
,
result
)
for
temp
in
temps
[::
-
1
]:
result
=
UtilNodes
.
EvalWithTempExprNode
(
temp
,
result
)
return
result
else
:
# PySet_New(it) is better than a generic Python call to set(it)
return
ExprNodes
.
PythonCapiCallNode
(
return
self
.
replace
(
node
,
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
"PySet_New"
,
self
.
PySet_New_func_type
,
args
=
pos_args
,
is_temp
=
node
.
is_temp
,
py_name
=
"set"
)
py_name
=
"set"
)
)
PyFrozenSet_New_func_type
=
PyrexTypes
.
CFuncType
(
Builtin
.
frozenset_type
,
[
...
...
tests/run/set.pyx
View file @
5765b020
...
...
@@ -144,6 +144,22 @@ def test_object_pop(s):
return
s
.
pop
()
def
test_noop_pop
():
"""
>>> test_noop_pop()
"""
set
([
0
]).
pop
()
def
test_noop_pop_exception
():
"""
>>> try: test_noop_pop_exception()
... except KeyError: pass
... else: print("KeyError expected but not raised!")
"""
set
([]).
pop
()
def
test_set_discard
():
"""
>>> type(test_set_discard()) is _set
...
...
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