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
fabff41b
Commit
fabff41b
authored
May 14, 2011
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code simplification in ForInStatNode
parent
6c486666
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
14 deletions
+8
-14
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+8
-12
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+0
-2
No files found.
Cython/Compiler/ExprNodes.py
View file @
fabff41b
...
...
@@ -1781,15 +1781,13 @@ class ImportNode(ExprNode):
class
IteratorNode
(
ExprNode
):
# Used as part of for statement implementation.
#
# allocate_counter_temp/release_counter_temp needs to be called
# by parent (ForInStatNode)
#
# Implements result = iter(sequence)
#
# sequence ExprNode
type
=
py_object_type
iter_func_ptr
=
None
counter_cname
=
None
subexprs
=
[
'sequence'
]
...
...
@@ -1808,13 +1806,6 @@ class IteratorNode(ExprNode):
gil_message
=
"Iterating over Python object"
def
allocate_counter_temp
(
self
,
code
):
self
.
counter_cname
=
code
.
funcstate
.
allocate_temp
(
PyrexTypes
.
c_py_ssize_t_type
,
manage_ref
=
False
)
def
release_counter_temp
(
self
,
code
):
code
.
funcstate
.
release_temp
(
self
.
counter_cname
)
_func_iternext_type
=
PyrexTypes
.
CPtrType
(
PyrexTypes
.
CFuncType
(
PyrexTypes
.
py_object_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"it"
,
PyrexTypes
.
py_object_type
,
None
),
...
...
@@ -1833,6 +1824,8 @@ class IteratorNode(ExprNode):
self
.
sequence
.
py_result
(),
self
.
sequence
.
py_result
()))
if
is_builtin_sequence
or
self
.
may_be_a_sequence
:
self
.
counter_cname
=
code
.
funcstate
.
allocate_temp
(
PyrexTypes
.
c_py_ssize_t_type
,
manage_ref
=
False
)
code
.
putln
(
"%s = 0; %s = %s; __Pyx_INCREF(%s);"
%
(
self
.
counter_cname
,
...
...
@@ -1844,8 +1837,8 @@ class IteratorNode(ExprNode):
if
self
.
may_be_a_sequence
:
code
.
putln
(
"%s = NULL;"
%
self
.
iter_func_ptr
)
code
.
putln
(
"} else {"
)
code
.
putln
(
"%s = -1; %s = PyObject_GetIter(%s); %s"
%
(
self
.
counter_cname
,
code
.
put
(
"%s = -1; "
%
self
.
counter_cname
)
code
.
putln
(
"%s = PyObject_GetIter(%s); %s"
%
(
self
.
result
(),
self
.
sequence
.
py_result
(),
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
...
...
@@ -1855,6 +1848,7 @@ class IteratorNode(ExprNode):
code
.
putln
(
"}"
)
def
generate_next_sequence_item
(
self
,
test_name
,
result_name
,
code
):
assert
self
.
counter_cname
,
"internal error: counter_cname temp not prepared"
code
.
putln
(
"if (%s >= Py%s_GET_SIZE(%s)) break;"
%
(
self
.
counter_cname
,
...
...
@@ -1901,6 +1895,8 @@ class IteratorNode(ExprNode):
code
.
putln
(
"}"
)
def
free_temps
(
self
,
code
):
if
self
.
counter_cname
:
code
.
funcstate
.
release_temp
(
self
.
counter_cname
)
if
self
.
iter_func_ptr
:
code
.
funcstate
.
release_temp
(
self
.
iter_func_ptr
)
self
.
iter_func_ptr
=
None
...
...
Cython/Compiler/Nodes.py
View file @
fabff41b
...
...
@@ -4644,7 +4644,6 @@ class ForInStatNode(LoopNode, StatNode):
def
generate_execution_code
(
self
,
code
):
old_loop_labels
=
code
.
new_loop_labels
()
self
.
iterator
.
allocate_counter_temp
(
code
)
self
.
iterator
.
generate_evaluation_code
(
code
)
code
.
putln
(
"for (;;) {"
)
self
.
item
.
generate_evaluation_code
(
code
)
...
...
@@ -4676,7 +4675,6 @@ class ForInStatNode(LoopNode, StatNode):
if
code
.
label_used
(
break_label
):
code
.
put_label
(
break_label
)
self
.
iterator
.
release_counter_temp
(
code
)
self
.
iterator
.
generate_disposal_code
(
code
)
self
.
iterator
.
free_temps
(
code
)
...
...
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