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
b36e1104
Commit
b36e1104
authored
Feb 10, 2018
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid redundant type check after calling "ext_type.__new__()" (and in some other cases).
parent
5af807ff
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
8 deletions
+15
-8
CHANGES.rst
CHANGES.rst
+2
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+9
-0
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+4
-8
No files found.
CHANGES.rst
View file @
b36e1104
...
...
@@ -51,6 +51,8 @@ Features added
* Single argument function calls can avoid the argument tuple creation in some cases.
* Some redundant extension type checks are avoided.
* Formatting C enum values in f-strings is faster, as well as some other special cases.
* Subscripting (item access) is faster in some cases.
...
...
Cython/Compiler/ExprNodes.py
View file @
b36e1104
...
...
@@ -12894,6 +12894,15 @@ class PyTypeTestNode(CoercionNode):
def
nonlocally_immutable
(
self
):
return
self
.
arg
.
nonlocally_immutable
()
def
reanalyse
(
self
):
if
self
.
type
!=
self
.
arg
.
type
or
not
self
.
arg
.
is_temp
:
return
self
if
not
self
.
type
.
typeobj_is_available
():
return
self
if
self
.
arg
.
may_be_none
()
and
self
.
notnone
:
return
self
.
arg
.
as_none_safe_node
(
"Cannot convert NoneType to %.200s"
%
self
.
type
.
name
)
return
self
.
arg
def
calculate_constant_result
(
self
):
# FIXME
pass
...
...
Cython/Compiler/Optimize.py
View file @
b36e1104
...
...
@@ -2024,16 +2024,11 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
"""
### cleanup to avoid redundant coercions to/from Python types
def
_visit_PyTypeTestNode
(
self
,
node
):
# disabled - appears to break assignments in some cases, and
# also drops a None check, which might still be required
def
visit_PyTypeTestNode
(
self
,
node
):
"""Flatten redundant type checks after tree changes.
"""
old_arg
=
node
.
arg
self
.
visitchildren
(
node
)
if
old_arg
is
node
.
arg
or
node
.
arg
.
type
!=
node
.
type
:
return
node
return
node
.
arg
return
node
.
reanalyse
()
def
_visit_TypecastNode
(
self
,
node
):
# disabled - the user may have had a reason to put a type
...
...
@@ -2804,7 +2799,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
PyTypeObjectPtr
=
PyrexTypes
.
CPtrType
(
cython_scope
.
lookup
(
'PyTypeObject'
).
type
)
pyx_tp_new_kwargs_func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
py_objec
t_type
,
[
ex
t_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"type"
,
PyTypeObjectPtr
,
None
),
PyrexTypes
.
CFuncTypeArg
(
"args"
,
PyrexTypes
.
py_object_type
,
None
),
PyrexTypes
.
CFuncTypeArg
(
"kwargs"
,
PyrexTypes
.
py_object_type
,
None
),
...
...
@@ -2817,6 +2812,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
node
.
pos
,
slot_func_cname
,
pyx_tp_new_kwargs_func_type
,
args
=
[
type_arg
,
args_tuple
,
kwargs
],
may_return_none
=
False
,
is_temp
=
True
)
else
:
# arbitrary variable, needs a None check for safety
...
...
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