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
74a20277
Commit
74a20277
authored
Oct 26, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
drop redundant specialisation code from for-in loop if we know it's not a list or tuple
parent
2fd9231a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
13 deletions
+19
-13
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+19
-13
No files found.
Cython/Compiler/ExprNodes.py
View file @
74a20277
...
...
@@ -1518,22 +1518,24 @@ class IteratorNode(ExprNode):
def
generate_result_code
(
self
,
code
):
is_builtin_sequence
=
self
.
sequence
.
type
is
list_type
or
\
self
.
sequence
.
type
is
tuple_type
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
())
el
s
e
:
el
if
may_be_a_sequenc
e
:
code
.
putln
(
"if (PyList_CheckExact(%s) || PyTuple_CheckExact(%s)) {"
%
(
self
.
sequence
.
py_result
(),
self
.
sequence
.
py_result
()))
code
.
putln
(
"%s = 0; %s = %s; __Pyx_INCREF(%s);"
%
(
self
.
counter_cname
,
self
.
result
(),
self
.
sequence
.
py_result
(),
self
.
result
()))
code
.
putln
(
"} else {"
)
if
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'
%
...
...
@@ -1545,7 +1547,8 @@ class IteratorNode(ExprNode):
self
.
sequence
.
py_result
(),
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
code
.
put_gotref
(
self
.
py_result
())
code
.
putln
(
"}"
)
if
may_be_a_sequence
:
code
.
putln
(
"}"
)
class
NextNode
(
AtomicExprNode
):
...
...
@@ -1564,12 +1567,15 @@ class NextNode(AtomicExprNode):
self
.
is_temp
=
1
def
generate_result_code
(
self
,
code
):
if
self
.
iterator
.
sequence
.
type
is
list_type
:
sequence_type
=
self
.
iterator
.
sequence
.
type
if
sequence_type
is
list_type
:
type_checks
=
[(
list_type
,
"List"
)]
elif
se
lf
.
iterator
.
sequence
.
type
is
tuple_type
:
elif
se
quence_
type
is
tuple_type
:
type_checks
=
[(
tuple_type
,
"Tuple"
)]
el
s
e
:
el
if
not
sequence_type
.
is_builtin_typ
e
:
type_checks
=
[(
list_type
,
"List"
),
(
tuple_type
,
"Tuple"
)]
else
:
type_checks
=
[]
for
py_type
,
prefix
in
type_checks
:
if
len
(
type_checks
)
>
1
:
...
...
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