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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
ed8aac8a
Commit
ed8aac8a
authored
Mar 02, 2011
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow pointer target in C array slice iteration to avoid expensive copying.
parent
7e01eaac
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
1 deletion
+25
-1
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+6
-1
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+3
-0
tests/run/carray_slicing.pyx
tests/run/carray_slicing.pyx
+16
-0
No files found.
Cython/Compiler/Nodes.py
View file @
ed8aac8a
...
...
@@ -4349,7 +4349,12 @@ class ForInStatNode(LoopNode, StatNode):
self
.
target
.
analyse_target_types
(
env
)
self
.
iterator
.
analyse_expressions
(
env
)
self
.
item
=
ExprNodes
.
NextNode
(
self
.
iterator
,
env
)
self
.
item
=
self
.
item
.
coerce_to
(
self
.
target
.
type
,
env
)
if
(
self
.
iterator
.
type
.
is_ptr
or
self
.
iterator
.
type
.
is_array
)
and
\
self
.
target
.
type
.
assignable_from
(
self
.
iterator
.
type
):
# C array slice optimization.
pass
else
:
self
.
item
=
self
.
item
.
coerce_to
(
self
.
target
.
type
,
env
)
self
.
body
.
analyse_expressions
(
env
)
if
self
.
else_clause
:
self
.
else_clause
.
analyse_expressions
(
env
)
...
...
Cython/Compiler/Optimize.py
View file @
ed8aac8a
...
...
@@ -375,6 +375,9 @@ class IterationTransform(Visitor.VisitorTransform):
base
=
counter_temp
,
type
=
Builtin
.
bytes_type
,
is_temp
=
1
)
elif
node
.
target
.
type
.
is_ptr
and
not
node
.
target
.
type
.
assignable_from
(
ptr_type
.
base_type
):
# Allow iteration with pointer target to avoid copy.
target_value
=
counter_temp
else
:
target_value
=
ExprNodes
.
IndexNode
(
node
.
target
.
pos
,
...
...
tests/run/carray_slicing.pyx
View file @
ed8aac8a
...
...
@@ -217,3 +217,19 @@ def iter_doublearray_for_loop_c():
"""
cdef
double
d
print
[
d
for
d
in
cdoubles
]
cdef
struct
MyStruct
:
int
i
def
struct_ptr_iter
():
"""
>>> struct_ptr_iter()
([0, 1, 2, 3, 4], [0, 1, 2, 3, 4])
"""
cdef
MyStruct
my_structs
[
5
]
for
i
in
range
(
5
):
my_structs
[
i
].
i
=
i
cdef
MyStruct
value
cdef
MyStruct
*
ptr
return
[
value
.
i
for
value
in
my_structs
[:
5
]
],
[
ptr
.
i
for
ptr
in
my_structs
[:
5
]
]
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