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
5f30f6b0
Commit
5f30f6b0
authored
Oct 29, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rewrite of C array iteration support to iterate directly over pointers instead of ints
parent
9765cf3c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
31 deletions
+33
-31
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+33
-31
No files found.
Cython/Compiler/Optimize.py
View file @
5f30f6b0
...
@@ -138,49 +138,51 @@ class IterationTransform(Visitor.VisitorTransform):
...
@@ -138,49 +138,51 @@ class IterationTransform(Visitor.VisitorTransform):
if
not
stop
:
if
not
stop
:
return
node
return
node
carray_ptr
=
slice_node
.
base
.
coerce_to_simple
(
self
.
current_scope
)
if
start
and
start
.
constant_result
!=
0
:
if
start
and
start
.
constant_result
!=
0
:
counter_type
=
PyrexTypes
.
spanning_type
(
start
.
type
,
stop
.
type
)
start_ptr_node
=
ExprNodes
.
AddNode
(
start
.
pos
,
operand1
=
carray_ptr
,
operator
=
'+'
,
operand2
=
start
,
type
=
carray_ptr
.
type
)
else
:
else
:
counter_type
=
stop
.
type
start_ptr_node
=
carray_ptr
start
=
ExprNodes
.
IntNode
(
slice_node
.
pos
,
value
=
0
,
type
=
counter_type
)
if
not
counter_type
.
is_int
:
# a Py_ssize_t should be enough for a pointer offset ...
counter_type
=
PyrexTypes
.
c_py_ssize_t_type
if
counter_type
!=
start
.
type
:
start
=
start
.
coerce_to
(
counter_type
,
self
.
current_scope
)
if
counter_type
!=
stop
.
type
:
stop
=
stop
.
coerce_to
(
counter_type
,
self
.
current_scope
)
start
=
start
.
coerce_to_simple
(
self
.
current_scope
)
stop_ptr_node
=
ExprNodes
.
AddNode
(
stop
=
stop
.
coerce_to_simple
(
self
.
current_scope
)
stop
.
pos
,
operand1
=
carray_ptr
,
operator
=
'+'
,
operand2
=
stop
,
type
=
carray_ptr
.
type
).
coerce_to_simple
(
self
.
current_scope
)
counter
=
UtilNodes
.
TempHandle
(
c
ounter_
type
)
counter
=
UtilNodes
.
TempHandle
(
c
array_ptr
.
type
)
counter_temp
=
counter
.
ref
(
node
.
target
.
pos
)
counter_temp
=
counter
.
ref
(
node
.
target
.
pos
)
# special case: char* -> bytes
if
slice_node
.
base
.
type
.
is_string
and
node
.
target
.
type
.
is_pyobject
:
if
slice_node
.
base
.
type
.
is_string
and
node
.
target
.
type
.
is_pyobject
:
# special case: char* -> bytes
target_value
=
ExprNodes
.
SliceIndexNode
(
target_value
=
ExprNodes
.
SliceIndexNode
(
node
.
target
.
pos
,
node
.
target
.
pos
,
start
=
counter_temp
,
start
=
ExprNodes
.
IntNode
(
node
.
target
.
pos
,
value
=
'0'
,
stop
=
ExprNodes
.
AddNode
(
constant_result
=
0
,
node
.
target
.
pos
,
type
=
PyrexTypes
.
c_int_type
),
operand1
=
counter_temp
,
stop
=
ExprNodes
.
IntNode
(
node
.
target
.
pos
,
value
=
'1'
,
operator
=
'+'
,
constant_result
=
1
,
operand2
=
ExprNodes
.
IntNode
(
node
.
target
.
pos
,
value
=
1
,
type
=
PyrexTypes
.
c_int_type
),
type
=
counter_temp
.
type
),
base
=
counter_temp
,
type
=
counter_temp
.
type
),
base
=
slice_node
.
base
,
type
=
Builtin
.
bytes_type
,
type
=
Builtin
.
bytes_type
,
is_temp
=
1
)
is_temp
=
1
)
else
:
else
:
target_value
=
ExprNodes
.
IndexNode
(
target_value
=
ExprNodes
.
IndexNode
(
node
.
target
.
pos
,
node
.
target
.
pos
,
index
=
counter_temp
,
index
=
ExprNodes
.
IntNode
(
node
.
target
.
pos
,
value
=
'0'
,
base
=
slice_node
.
base
,
constant_result
=
0
,
type
=
PyrexTypes
.
c_int_type
),
base
=
counter_temp
,
is_buffer_access
=
False
,
is_buffer_access
=
False
,
type
=
slice_node
.
base
.
type
.
base_type
)
type
=
carray_ptr
.
type
.
base_type
)
if
target_value
.
type
!=
node
.
target
.
type
:
if
target_value
.
type
!=
node
.
target
.
type
:
target_value
=
target_value
.
coerce_to
(
node
.
target
.
type
,
target_value
=
target_value
.
coerce_to
(
node
.
target
.
type
,
...
@@ -197,9 +199,9 @@ class IterationTransform(Visitor.VisitorTransform):
...
@@ -197,9 +199,9 @@ class IterationTransform(Visitor.VisitorTransform):
for_node
=
Nodes
.
ForFromStatNode
(
for_node
=
Nodes
.
ForFromStatNode
(
node
.
pos
,
node
.
pos
,
bound1
=
start
,
relation1
=
'<='
,
bound1
=
start
_ptr_node
,
relation1
=
'<='
,
target
=
counter_temp
,
target
=
counter_temp
,
relation2
=
'<'
,
bound2
=
stop
,
relation2
=
'<'
,
bound2
=
stop
_ptr_node
,
step
=
step
,
body
=
body
,
step
=
step
,
body
=
body
,
else_clause
=
node
.
else_clause
,
else_clause
=
node
.
else_clause
,
from_range
=
True
)
from_range
=
True
)
...
@@ -300,7 +302,7 @@ class IterationTransform(Visitor.VisitorTransform):
...
@@ -300,7 +302,7 @@ class IterationTransform(Visitor.VisitorTransform):
constant_result
=
step_value
)
constant_result
=
step_value
)
if
step_value
<
0
:
if
step_value
<
0
:
step
.
value
=
-
step_value
step
.
value
=
str
(
-
step_value
)
relation1
=
'>='
relation1
=
'>='
relation2
=
'>'
relation2
=
'>'
else
:
else
:
...
...
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