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
3e431781
Commit
3e431781
authored
Jul 11, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more readable for-loop code, optimise tuples the way lists are optimised (basically no overhead)
parent
5e1164c6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
9 deletions
+30
-9
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+17
-7
tests/run/r_forloop.pyx
tests/run/r_forloop.pyx
+13
-2
No files found.
Cython/Compiler/ExprNodes.py
View file @
3e431781
...
...
@@ -1145,16 +1145,22 @@ class IteratorNode(ExprNode):
def
generate_result_code
(
self
,
code
):
code
.
putln
(
"if (PyList_CheckExact(%s)
) { %s = 0; %s = %s; Py_INCREF(%s); }
"
%
(
"if (PyList_CheckExact(%s)
|| PyTuple_CheckExact(%s)) {
"
%
(
self
.
sequence
.
py_result
(),
self
.
sequence
.
py_result
()))
code
.
putln
(
"%s = 0; %s = %s; Py_INCREF(%s);"
%
(
self
.
counter
.
result_code
,
self
.
result_code
,
self
.
sequence
.
py_result
(),
self
.
result_code
))
code
.
putln
(
"else { %s = PyObject_GetIter(%s); %s }"
%
(
code
.
putln
(
"} else {"
)
code
.
putln
(
"%s = -1; %s = PyObject_GetIter(%s); %s"
%
(
self
.
counter
.
result_code
,
self
.
result_code
,
self
.
sequence
.
py_result
(),
code
.
error_goto_if_null
(
self
.
result_code
,
self
.
pos
)))
code
.
putln
(
"}"
)
class
NextNode
(
AtomicExprNode
):
...
...
@@ -1173,15 +1179,19 @@ class NextNode(AtomicExprNode):
def
generate_result_code
(
self
,
code
):
code
.
putln
(
"if (PyList_CheckExact(%s)) { if (%s >= PyList_GET_SIZE(%s)) break; %s = PyList_GET_ITEM(%s, %s++); Py_INCREF(%s); }"
%
(
self
.
iterator
.
py_result
(),
"if (likely(%s != -1)) {"
%
self
.
iterator
.
counter
.
result_code
)
code
.
putln
(
"if (%s >= PySequence_Fast_GET_SIZE(%s)) break;"
%
(
self
.
iterator
.
counter
.
result_code
,
self
.
iterator
.
py_result
(),
self
.
iterator
.
py_result
()))
code
.
putln
(
"%s = PySequence_Fast_GET_ITEM(%s, %s); Py_INCREF(%s); %s++;"
%
(
self
.
result_code
,
self
.
iterator
.
py_result
(),
self
.
iterator
.
counter
.
result_code
,
self
.
result_code
))
code
.
putln
(
"else {"
)
self
.
result_code
,
self
.
iterator
.
counter
.
result_code
))
code
.
putln
(
"} else {"
)
code
.
putln
(
"%s = PyIter_Next(%s);"
%
(
self
.
result_code
,
...
...
tests/run/r_forloop.pyx
View file @
3e431781
__doc__
=
u"""
>>> go()
>>> go_py()
Spam!
Spam!
Spam!
Spam!
Spam!
>>> go_c()
Spam!
Spam!
Spam!
...
...
@@ -7,7 +14,11 @@ __doc__ = u"""
Spam!
"""
def
go
():
def
go
_py
():
for
i
in
range
(
5
):
print
u"Spam!"
def
go_c
():
cdef
int
i
for
i
in
range
(
5
):
print
u"Spam!"
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