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
e969ef32
Commit
e969ef32
authored
Mar 16, 2019
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify optimisation code for cascaded comparisons and improve its test coverage.
parent
714123e3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
23 deletions
+42
-23
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+4
-6
tests/compile/cascmp.pyx
tests/compile/cascmp.pyx
+0
-17
tests/run/cascmp.pyx
tests/run/cascmp.pyx
+38
-0
No files found.
Cython/Compiler/Optimize.py
View file @
e969ef32
...
...
@@ -4527,22 +4527,20 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
cascades
=
[[
node
.
operand1
]]
final_false_result
=
[]
def
split_cascades
(
cmp_node
):
cmp_node
=
node
while
cmp_node
is
not
None
:
if
cmp_node
.
has_constant_result
():
if
not
cmp_node
.
constant_result
:
# False => short-circuit
final_false_result
.
append
(
self
.
_bool_node
(
cmp_node
,
False
))
return
break
else
:
# True => discard and start new cascade
cascades
.
append
([
cmp_node
.
operand2
])
else
:
# not constant => append to current cascade
cascades
[
-
1
].
append
(
cmp_node
)
if
cmp_node
.
cascade
:
split_cascades
(
cmp_node
.
cascade
)
split_cascades
(
node
)
cmp_node
=
cmp_node
.
cascade
cmp_nodes
=
[]
for
cascade
in
cascades
:
...
...
tests/compile/cascmp.pyx
deleted
100644 → 0
View file @
714123e3
# mode: compile
cdef
void
foo
():
cdef
int
bool
,
int1
=
0
,
int2
=
0
,
int3
=
0
,
int4
=
0
cdef
object
obj1
,
obj2
,
obj3
,
obj4
obj1
=
1
obj2
=
2
obj3
=
3
obj4
=
4
bool
=
int1
<
int2
<
int3
bool
=
obj1
<
obj2
<
obj3
bool
=
int1
<
int2
<
obj3
bool
=
obj1
<
2
<
3
bool
=
obj1
<
2
<
3
<
4
bool
=
int1
<
(
int2
==
int3
)
<
int4
foo
()
tests/run/cascmp.pyx
0 → 100644
View file @
e969ef32
# mode: run
# tag: cascade, compare
def
ints_and_objects
():
"""
>>> ints_and_objects()
(0, 1, 0, 1, 1, 0)
"""
cdef
int
int1
=
0
,
int2
=
0
,
int3
=
0
,
int4
=
0
cdef
int
r1
,
r2
,
r3
,
r4
,
r5
,
r6
cdef
object
obj1
,
obj2
,
obj3
,
obj4
obj1
=
1
obj2
=
2
obj3
=
3
obj4
=
4
r1
=
int1
<
int2
<
int3
r2
=
obj1
<
obj2
<
obj3
r3
=
int1
<
int2
<
obj3
r4
=
obj1
<
2
<
3
r5
=
obj1
<
2
<
3
<
4
r6
=
int1
<
(
int2
==
int3
)
<
int4
return
r1
,
r2
,
r3
,
r4
,
r5
,
r6
def
const_cascade
(
x
):
"""
>>> const_cascade(2)
(True, False, True, False, False, True, False)
"""
return
(
0
<=
1
,
1
<=
0
,
1
<=
1
<=
2
,
1
<=
0
<
1
,
1
<=
1
<=
0
,
1
<=
1
<=
x
<=
2
<=
3
>
x
<=
2
<=
2
,
1
<=
1
<=
x
<=
1
<=
1
<=
x
<=
2
,
)
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