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
591199d1
Commit
591199d1
authored
Aug 14, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimise iteration over dict(...kwargs...).items() etc. and not only dict(*args).items() etc.
parent
37566326
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
1 deletion
+26
-1
CHANGES.rst
CHANGES.rst
+3
-0
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+1
-1
tests/run/iterdict.pyx
tests/run/iterdict.pyx
+22
-0
No files found.
CHANGES.rst
View file @
591199d1
...
...
@@ -27,6 +27,9 @@ Bugs fixed
* ``isinf()`` declarations in ``libc/math.pxd`` and ``numpy/math.pxd`` now
reflect the actual tristate ``int`` return value instead of using ``bint``.
* Iteration over ``dict(...).items()`` failed to get optimised when dict
arguments included keyword arguments.
Other changes
-------------
...
...
Cython/Compiler/Optimize.py
View file @
591199d1
...
...
@@ -211,7 +211,7 @@ class IterationTransform(Visitor.EnvTransform):
if
not
is_safe_iter
and
method
in
(
'keys'
,
'values'
,
'items'
):
# try to reduce this to the corresponding .iter*() methods
if
isinstance
(
base_obj
,
ExprNodes
.
Simple
CallNode
):
if
isinstance
(
base_obj
,
ExprNodes
.
CallNode
):
inner_function
=
base_obj
.
function
if
(
inner_function
.
is_name
and
inner_function
.
name
==
'dict'
and
inner_function
.
entry
...
...
tests/run/iterdict.pyx
View file @
591199d1
...
...
@@ -505,3 +505,25 @@ def values_of_expression(**kwargs):
"""
# this can be optimised even in Py2
return
[
arg
for
arg
in
dict
(
kwargs
.
items
()).
values
()
]
def
items_of_expression
(
*
args
,
**
kwargs
):
"""
>>> sorted(items_of_expression(a=3, b=4))
[('a', 3), ('b', 4)]
>>> sorted(items_of_expression([('a', 3)], b=4))
[('a', 3), ('b', 4)]
"""
return
[
item
for
item
in
dict
(
*
args
,
**
kwargs
).
items
()]
def
iteritems_of_expression
(
*
args
,
**
kwargs
):
"""
>>> sorted(iteritems_of_expression(a=3, b=4))
[('a', 3), ('b', 4)]
>>> sorted(iteritems_of_expression([('a', 3)], b=4))
[('a', 3), ('b', 4)]
"""
return
[
item
for
item
in
dict
(
*
args
,
**
kwargs
).
iteritems
()]
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