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
ee6bbddb
Commit
ee6bbddb
authored
Nov 19, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
generate expected code when for-looping over type-declared list or tuple
parent
6d083814
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
15 deletions
+38
-15
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+38
-15
No files found.
Cython/Compiler/ExprNodes.py
View file @
ee6bbddb
...
...
@@ -1340,6 +1340,12 @@ class IteratorNode(ExprNode):
self
.
counter
.
release_temp
(
env
)
def
generate_result_code
(
self
,
code
):
is_builtin_sequence
=
self
.
sequence
.
type
is
list_type
or
\
self
.
sequence
.
type
is
tuple_type
if
is_builtin_sequence
:
code
.
putln
(
"if (likely(%s != Py_None)) {"
%
self
.
sequence
.
py_result
())
else
:
code
.
putln
(
"if (PyList_CheckExact(%s) || PyTuple_CheckExact(%s)) {"
%
(
self
.
sequence
.
py_result
(),
...
...
@@ -1351,6 +1357,11 @@ class IteratorNode(ExprNode):
self
.
sequence
.
py_result
(),
self
.
result
()))
code
.
putln
(
"} else {"
)
if
is_builtin_sequence
:
code
.
putln
(
'PyErr_SetString(PyExc_TypeError, "
\
'
NoneType
\
'
object is not iterable"); %s'
%
code
.
error_goto
(
self
.
pos
))
else
:
code
.
putln
(
"%s = -1; %s = PyObject_GetIter(%s); %s"
%
(
self
.
counter
.
result
(),
self
.
result
(),
...
...
@@ -1374,23 +1385,35 @@ class NextNode(AtomicExprNode):
self
.
is_temp
=
1
def
generate_result_code
(
self
,
code
):
for
py_type
in
[
"List"
,
"Tuple"
]:
if
self
.
iterator
.
sequence
.
type
is
list_type
:
type_checks
=
[(
list_type
,
"List"
)]
elif
self
.
iterator
.
sequence
.
type
is
tuple_type
:
type_checks
=
[(
tuple_type
,
"Tuple"
)]
else
:
type_checks
=
[(
list_type
,
"List"
),
(
tuple_type
,
"Tuple"
)]
for
py_type
,
prefix
in
type_checks
:
if
len
(
type_checks
)
>
1
:
code
.
putln
(
"if (likely(Py%s_CheckExact(%s))) {"
%
(
py_type
,
self
.
iterator
.
py_result
()))
"if (likely(Py%s_CheckExact(%s))) {"
%
(
prefix
,
self
.
iterator
.
py_result
()))
code
.
putln
(
"if (%s >= Py%s_GET_SIZE(%s)) break;"
%
(
self
.
iterator
.
counter
.
result
(),
p
y_type
,
p
refix
,
self
.
iterator
.
py_result
()))
code
.
putln
(
"%s = Py%s_GET_ITEM(%s, %s); Py_INCREF(%s); %s++;"
%
(
self
.
result
(),
p
y_type
,
p
refix
,
self
.
iterator
.
py_result
(),
self
.
iterator
.
counter
.
result
(),
self
.
result
(),
self
.
iterator
.
counter
.
result
()))
if
len
(
type_checks
)
>
1
:
code
.
put
(
"} else "
)
if
len
(
type_checks
)
==
1
:
return
code
.
putln
(
"{"
)
code
.
putln
(
"%s = PyIter_Next(%s);"
%
(
...
...
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