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
63f591a3
Commit
63f591a3
authored
Dec 27, 2014
by
root
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimized reversed range with negative steps.
parent
4f0ff235
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
8 deletions
+15
-8
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+15
-8
No files found.
Cython/Compiler/Optimize.py
View file @
63f591a3
...
@@ -661,23 +661,30 @@ class IterationTransform(Visitor.EnvTransform):
...
@@ -661,23 +661,30 @@ class IterationTransform(Visitor.EnvTransform):
if
reversed
:
if
reversed
:
bound1
,
bound2
=
bound2
,
bound1
bound1
,
bound2
=
bound2
,
bound1
if
step_value
<
0
:
if
step_value
<
0
:
if
step_value
!=
-
1
:
# FIXME: not currently supported
return
node
step_value
=
-
step_value
step_value
=
-
step_value
if
step_value
!=
1
:
if
step_value
!=
1
:
begin_value
=
bound2
.
constant_result
end_value
=
bound1
.
constant_result
if
isinstance
(
begin_value
,
(
int
,
long
))
and
isinstance
(
end_value
,
(
int
,
long
)):
bound1_value
=
begin_value
-
step_value
*
((
begin_value
-
end_value
-
1
)
//
step_value
)
-
1
bound1
=
ExprNodes
.
IntNode
(
bound1
.
pos
,
value
=
str
(
bound1_value
),
constant_result
=
bound1_value
,
type
=
PyrexTypes
.
spanning_type
(
bound1
.
type
,
bound2
.
type
))
else
:
# FIXME: Optimize when variable is in range (e.g. reversed(range(x, y, -3)))
return
node
elif
step_value
!=
1
:
begin_value
=
bound1
.
constant_result
begin_value
=
bound1
.
constant_result
end_value
=
bound2
.
constant_result
end_value
=
bound2
.
constant_result
if
isinstance
(
begin_value
,
(
int
,
long
))
and
isinstance
(
end_value
,
(
int
,
long
)):
if
isinstance
(
begin_value
,
(
int
,
long
))
and
isinstance
(
end_value
,
(
int
,
long
)):
bound1_value
=
step_value
*
((
begin_value
-
end_value
-
1
)
//
step_value
)
+
end_value
+
1
bound1_value
=
end_value
+
step_value
*
((
begin_value
-
end_value
-
1
)
//
step_value
)
+
1
bound1
=
ExprNodes
.
IntNode
(
bound1
=
ExprNodes
.
IntNode
(
bound1
.
pos
,
value
=
str
(
bound1_value
),
constant_result
=
bound1_value
,
bound1
.
pos
,
value
=
str
(
bound1_value
),
constant_result
=
bound1_value
,
type
=
PyrexTypes
.
spanning_type
(
bound1
.
type
,
bound2
.
type
))
type
=
PyrexTypes
.
spanning_type
(
bound1
.
type
,
bound2
.
type
))
else
:
else
:
# FIXME: Optimize when variable is in range (e.g. reversed(range(x, y, 3)))
# FIXME: Optimize when variable is in range (e.g. reversed(range(x, y, 3)))
return
node
return
node
else
:
elif
step_value
<
0
:
if
step_value
<
0
:
step_value
=
-
step_value
step_value
=
-
step_value
step
.
value
=
str
(
step_value
)
step
.
value
=
str
(
step_value
)
...
...
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