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
d54e9d52
Commit
d54e9d52
authored
Nov 30, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reduce code redundancy in IterationNode, skip None test if we know the iterable is not None
parent
24135871
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
14 deletions
+11
-14
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+11
-14
No files found.
Cython/Compiler/ExprNodes.py
View file @
d54e9d52
...
...
@@ -1770,6 +1770,9 @@ class IteratorNode(ExprNode):
self
.
type
=
self
.
sequence
.
type
else
:
self
.
sequence
=
self
.
sequence
.
coerce_to_pyobject
(
env
)
if
self
.
sequence
.
type
is
list_type
or
\
self
.
sequence
.
type
is
tuple_type
:
self
.
sequence
=
self
.
sequence
.
as_none_safe_node
(
"'NoneType' object is not iterable"
)
self
.
is_temp
=
1
gil_message
=
"Iterating over Python object"
...
...
@@ -1786,36 +1789,30 @@ class IteratorNode(ExprNode):
raise
InternalError
(
"for in carray slice not transformed"
)
is_builtin_sequence
=
self
.
sequence
.
type
is
list_type
or
\
self
.
sequence
.
type
is
tuple_type
may_be_a_sequence
=
is_builtin_sequence
or
not
self
.
sequence
.
type
.
is_builtin_type
if
is_builtin_sequence
:
code
.
putln
(
"if (likely(%s != Py_None)) {"
%
self
.
sequence
.
py_result
())
elif
may_be_a_sequence
:
may_be_a_sequence
=
not
self
.
sequence
.
type
.
is_builtin_type
if
may_be_a_sequence
:
code
.
putln
(
"if (PyList_CheckExact(%s) || PyTuple_CheckExact(%s)) {"
%
(
self
.
sequence
.
py_result
(),
self
.
sequence
.
py_result
()))
if
may_be_a_sequence
:
if
is_builtin_sequence
or
may_be_a_sequence
:
code
.
putln
(
"%s = 0; %s = %s; __Pyx_INCREF(%s);"
%
(
self
.
counter_cname
,
self
.
result
(),
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
:
if
not
is_builtin_sequence
:
if
may_be_a_sequence
:
code
.
putln
(
"} else {"
)
code
.
putln
(
"%s = -1; %s = PyObject_GetIter(%s); %s"
%
(
self
.
counter_cname
,
self
.
result
(),
self
.
sequence
.
py_result
(),
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
code
.
put_gotref
(
self
.
py_result
())
if
may_be_a_sequence
:
code
.
putln
(
"}"
)
if
may_be_a_sequence
:
code
.
putln
(
"}"
)
class
NextNode
(
AtomicExprNode
):
...
...
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