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
7c89ca3e
Commit
7c89ca3e
authored
Aug 21, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify and extend in/not-in and is/is-not optimisation, add test
parent
c988f6e4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
14 deletions
+87
-14
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+15
-14
tests/run/isnot.pyx
tests/run/isnot.pyx
+72
-0
No files found.
Cython/Compiler/Optimize.py
View file @
7c89ca3e
...
...
@@ -19,6 +19,7 @@ from StringEncoding import EncodedString, BytesLiteral
from
Errors
import
error
from
ParseTreeTransforms
import
SkipDeclarations
import
copy
import
codecs
try
:
...
...
@@ -3068,21 +3069,21 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
return
self
.
_handle_UnaryMinusNode
(
node
)
return
node
_negate_operator
=
{
'in'
:
'not_in'
,
'not_in'
:
'in'
,
'is'
:
'is_not'
,
'is_not'
:
'is'
}.
get
def
_handle_UnaryNotNode
(
self
,
node
):
if
isinstance
(
node
.
operand
,
ExprNodes
.
PrimaryCmpNode
):
cmp_node
=
node
.
operand
if
cmp_node
.
operator
==
'in'
:
operator
=
'not_in'
elif
cmp_node
.
operator
==
'is'
:
operator
=
'is_not'
else
:
return
node
return
ExprNodes
.
PrimaryCmpNode
(
cmp_node
.
pos
,
operand1
=
cmp_node
.
operand1
,
operand2
=
cmp_node
.
operand2
,
operator
=
operator
,
cascade
=
cmp_node
.
cascade
)
operand
=
node
.
operand
if
isinstance
(
operand
,
ExprNodes
.
PrimaryCmpNode
):
operator
=
self
.
_negate_operator
(
operand
.
operator
)
if
operator
:
node
=
copy
.
copy
(
operand
)
node
.
operator
=
operator
node
=
self
.
visit_PrimaryCmpNode
(
node
)
return
node
def
_handle_UnaryMinusNode
(
self
,
node
):
...
...
tests/run/isnot.pyx
0 → 100644
View file @
7c89ca3e
# mode: run
# tag: is_not
cimport
cython
@
cython
.
test_fail_if_path_exists
(
'//NotNode'
)
def
is_not
(
a
,
b
):
"""
>>> is_not(1, 2)
True
>>> x = 1
>>> is_not(x, x)
False
"""
return
a
is
not
b
@
cython
.
test_fail_if_path_exists
(
'//NotNode'
)
def
not_is_not
(
a
,
b
):
"""
>>> not_is_not(1, 2)
False
>>> x = 1
>>> not_is_not(x, x)
True
"""
return
not
a
is
not
b
@
cython
.
test_fail_if_path_exists
(
'//NotNode'
)
def
not_is
(
a
,
b
):
"""
>>> not_is(1, 2)
True
>>> x = 1
>>> not_is(x, x)
False
"""
return
not
a
is
b
@
cython
.
test_fail_if_path_exists
(
'//NotNode'
)
def
is_not_None
(
a
):
"""
>>> is_not_None(1)
True
>>> is_not_None(None)
False
"""
return
a
is
not
None
@
cython
.
test_fail_if_path_exists
(
'//NotNode'
)
def
not_is_not_None
(
a
):
"""
>>> not_is_not_None(1)
False
>>> not_is_not_None(None)
True
"""
return
not
a
is
not
None
@
cython
.
test_fail_if_path_exists
(
'//NotNode'
)
def
not_is_None
(
a
):
"""
>>> not_is_None(1)
True
>>> not_is_None(None)
False
"""
return
not
a
is
None
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