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
54adfe2d
Commit
54adfe2d
authored
Feb 08, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimise set(it) into a call to PySet_New(it)
parent
e40d032f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
18 deletions
+32
-18
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+32
-18
No files found.
Cython/Compiler/Optimize.py
View file @
54adfe2d
...
...
@@ -1993,25 +1993,39 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
exception_value
=
"((double)-1)"
,
exception_check
=
True
)
PySet_New_func_type
=
PyrexTypes
.
CFuncType
(
Builtin
.
set_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"it"
,
PyrexTypes
.
py_object_type
,
None
)
])
def
_handle_simple_function_set
(
self
,
node
,
function
,
pos_args
):
if
len
(
pos_args
)
==
1
and
isinstance
(
pos_args
[
0
],
(
ExprNodes
.
ListNode
,
ExprNodes
.
TupleNode
)):
# We can optimise set([x,y,z]) safely into a set literal,
# but only if we create all items before adding them -
# adding an item may raise an exception if it is not
# hashable, but creating the later items may have
# side-effects.
args
=
[]
temps
=
[]
for
arg
in
pos_args
[
0
].
args
:
if
not
arg
.
is_simple
():
arg
=
UtilNodes
.
LetRefNode
(
arg
)
temps
.
append
(
arg
)
args
.
append
(
arg
)
result
=
ExprNodes
.
SetNode
(
node
.
pos
,
is_temp
=
1
,
args
=
args
)
for
temp
in
temps
[::
-
1
]:
result
=
UtilNodes
.
EvalWithTempExprNode
(
temp
,
result
)
return
result
if
len
(
pos_args
)
==
1
:
if
pos_args
[
0
].
is_sequence_constructor
:
# We can optimise set([x,y,z]) safely into a set literal,
# but only if we create all items before adding them -
# adding an item may raise an exception if it is not
# hashable, but creating the later items may have
# side-effects.
args
=
[]
temps
=
[]
for
arg
in
pos_args
[
0
].
args
:
if
not
arg
.
is_simple
():
arg
=
UtilNodes
.
LetRefNode
(
arg
)
temps
.
append
(
arg
)
args
.
append
(
arg
)
result
=
ExprNodes
.
SetNode
(
node
.
pos
,
is_temp
=
1
,
args
=
args
)
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
(
node
.
pos
,
"PySet_New"
,
self
.
PySet_New_func_type
,
args
=
pos_args
,
is_temp
=
node
.
is_temp
,
utility_code
=
UtilityCode
.
load_cached
(
'pyset_compat'
,
'Builtins.c'
),
py_name
=
"set"
)
return
node
def
_handle_simple_function_float
(
self
,
node
,
function
,
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