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
78aa444d
Commit
78aa444d
authored
May 29, 2020
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid hasattr()+getattr pattern in favour of a single lookup.
parent
55309f78
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
32 deletions
+37
-32
Cython/Compiler/AutoDocTransforms.py
Cython/Compiler/AutoDocTransforms.py
+3
-2
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+25
-20
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+5
-6
Cython/Compiler/UtilNodes.py
Cython/Compiler/UtilNodes.py
+4
-4
No files found.
Cython/Compiler/AutoDocTransforms.py
View file @
78aa444d
...
...
@@ -217,8 +217,9 @@ class EmbedSignature(CythonTransform):
old_doc
=
None
new_doc
=
self
.
_embed_signature
(
signature
,
old_doc
)
node
.
entry
.
doc
=
EncodedString
(
new_doc
)
if
hasattr
(
node
,
'py_func'
)
and
node
.
py_func
is
not
None
:
node
.
py_func
.
entry
.
doc
=
EncodedString
(
new_doc
)
py_func
=
getattr
(
node
,
'py_func'
,
None
)
if
py_func
is
not
None
:
py_func
.
entry
.
doc
=
EncodedString
(
new_doc
)
return
node
def
visit_PropertyNode
(
self
,
node
):
...
...
Cython/Compiler/ExprNodes.py
View file @
78aa444d
...
...
@@ -631,7 +631,7 @@ class ExprNode(Node):
def
type_dependencies
(
self
,
env
):
# Returns the list of entries whose types must be determined
# before the type of self can be inferred.
if
hasattr
(
self
,
'type'
)
and
self
.
type
is
not
None
:
if
getattr
(
self
,
'type'
,
None
)
is
not
None
:
return
()
return
sum
([
node
.
type_dependencies
(
env
)
for
node
in
self
.
subexpr_nodes
()],
())
...
...
@@ -640,12 +640,13 @@ class ExprNode(Node):
# Differs from analyse_types as it avoids unnecessary
# analysis of subexpressions, but can assume everything
# in self.type_dependencies() has been resolved.
if
hasattr
(
self
,
'type'
)
and
self
.
type
is
not
None
:
return
self
.
type
elif
hasattr
(
self
,
'entry'
)
and
self
.
entry
is
not
None
:
return
self
.
entry
.
type
else
:
self
.
not_implemented
(
"infer_type"
)
type
=
getattr
(
self
,
'type'
,
None
)
if
type
is
not
None
:
return
type
entry
=
getattr
(
self
,
'entry'
,
None
)
if
entry
is
not
None
:
return
entry
.
type
self
.
not_implemented
(
"infer_type"
)
def
nonlocally_immutable
(
self
):
# Returns whether this variable is a safe reference, i.e.
...
...
@@ -2243,7 +2244,6 @@ class NameNode(AtomicExprNode):
return
entry
.
cname
def
generate_result_code
(
self
,
code
):
assert
hasattr
(
self
,
'entry'
)
entry
=
self
.
entry
if
entry
is
None
:
return
# There was an error earlier
...
...
@@ -2533,7 +2533,7 @@ class NameNode(AtomicExprNode):
error
(
self
.
pos
,
"Deletion of C names not supported"
)
def
annotate
(
self
,
code
):
if
hasattr
(
self
,
'is_called'
)
and
self
.
is_called
:
if
getattr
(
self
,
'is_called'
,
False
)
:
pos
=
(
self
.
pos
[
0
],
self
.
pos
[
1
],
self
.
pos
[
2
]
-
len
(
self
.
name
)
-
1
)
if
self
.
type
.
is_pyobject
:
style
,
text
=
'py_call'
,
'python function (%s)'
...
...
@@ -6977,7 +6977,7 @@ class AttributeNode(ExprNode):
return
module_scope
.
lookup_type
(
self
.
attribute
)
if
not
self
.
obj
.
is_string_literal
:
base_type
=
self
.
obj
.
analyse_as_type
(
env
)
if
base_type
and
hasattr
(
base_type
,
'scope'
)
and
base_type
.
scope
is
not
None
:
if
base_type
and
getattr
(
base_type
,
'scope'
,
None
)
is
not
None
:
return
base_type
.
scope
.
lookup_type
(
self
.
attribute
)
return
None
...
...
@@ -13525,11 +13525,13 @@ class ProxyNode(CoercionNode):
return
self
.
arg
.
infer_type
(
env
)
def
_proxy_type
(
self
):
if
hasattr
(
self
.
arg
,
'type'
):
self
.
type
=
self
.
arg
.
type
type
=
getattr
(
self
.
arg
,
'type'
,
None
)
if
type
:
self
.
type
=
type
self
.
result_ctype
=
self
.
arg
.
result_ctype
if
hasattr
(
self
.
arg
,
'entry'
):
self
.
entry
=
self
.
arg
.
entry
arg_entry
=
getattr
(
self
.
arg
,
'entry'
,
None
)
if
arg_entry
:
self
.
entry
=
arg_entry
def
generate_result_code
(
self
,
code
):
self
.
arg
.
generate_result_code
(
code
)
...
...
@@ -13566,11 +13568,13 @@ class CloneNode(CoercionNode):
def
__init__
(
self
,
arg
):
CoercionNode
.
__init__
(
self
,
arg
)
self
.
constant_result
=
arg
.
constant_result
if
hasattr
(
arg
,
'type'
):
self
.
type
=
arg
.
type
type
=
getattr
(
arg
,
'type'
,
None
)
if
type
:
self
.
type
=
type
self
.
result_ctype
=
arg
.
result_ctype
if
hasattr
(
arg
,
'entry'
):
self
.
entry
=
arg
.
entry
arg_entry
=
getattr
(
arg
,
'entry'
,
None
)
if
arg_entry
:
self
.
entry
=
arg_entry
def
result
(
self
):
return
self
.
arg
.
result
()
...
...
@@ -13588,8 +13592,9 @@ class CloneNode(CoercionNode):
self
.
type
=
self
.
arg
.
type
self
.
result_ctype
=
self
.
arg
.
result_ctype
self
.
is_temp
=
1
if
hasattr
(
self
.
arg
,
'entry'
):
self
.
entry
=
self
.
arg
.
entry
arg_entry
=
getattr
(
self
.
arg
,
'entry'
,
None
)
if
arg_entry
:
self
.
entry
=
arg_entry
return
self
def
coerce_to
(
self
,
dest_type
,
env
):
...
...
Cython/Compiler/Nodes.py
View file @
78aa444d
...
...
@@ -895,8 +895,9 @@ class CArgDeclNode(Node):
could_be_name
=
False
self
.
base_type
.
is_arg
=
True
base_type
=
self
.
base_type
.
analyse
(
env
,
could_be_name
=
could_be_name
)
if
hasattr
(
self
.
base_type
,
'arg_name'
)
and
self
.
base_type
.
arg_name
:
self
.
declarator
.
name
=
self
.
base_type
.
arg_name
base_arg_name
=
getattr
(
self
.
base_type
,
'arg_name'
,
None
)
if
base_arg_name
:
self
.
declarator
.
name
=
base_arg_name
# The parser is unable to resolve the ambiguity of [] as part of the
# type (e.g. in buffers) or empty declarator (as with arrays).
...
...
@@ -9319,9 +9320,6 @@ class ParallelRangeNode(ParallelStatNode):
else
:
self
.
start
,
self
.
stop
,
self
.
step
=
self
.
args
if
hasattr
(
self
.
schedule
,
'decode'
):
self
.
schedule
=
self
.
schedule
.
decode
(
'ascii'
)
if
self
.
schedule
not
in
(
None
,
'static'
,
'dynamic'
,
'guided'
,
'runtime'
):
error
(
self
.
pos
,
"Invalid schedule argument to prange: %s"
%
(
self
.
schedule
,))
...
...
@@ -9380,7 +9378,8 @@ class ParallelRangeNode(ParallelStatNode):
# ensure lastprivate behaviour and propagation. If the target index is
# not a NameNode, it won't have an entry, and an error was issued by
# ParallelRangeTransform
if
hasattr
(
self
.
target
,
'entry'
):
target_entry
=
getattr
(
self
.
target
,
'entry'
,
None
)
if
target_entry
:
self
.
assignments
[
self
.
target
.
entry
]
=
self
.
target
.
pos
,
None
node
=
super
(
ParallelRangeNode
,
self
).
analyse_expressions
(
env
)
...
...
Cython/Compiler/UtilNodes.py
View file @
78aa444d
...
...
@@ -122,8 +122,7 @@ class ResultRefNode(AtomicExprNode):
self
.
may_hold_none
=
may_hold_none
if
expression
is
not
None
:
self
.
pos
=
expression
.
pos
if
hasattr
(
expression
,
"type"
):
self
.
type
=
expression
.
type
self
.
type
=
getattr
(
expression
,
"type"
,
None
)
if
pos
is
not
None
:
self
.
pos
=
pos
if
type
is
not
None
:
...
...
@@ -144,8 +143,9 @@ class ResultRefNode(AtomicExprNode):
def
update_expression
(
self
,
expression
):
self
.
expression
=
expression
if
hasattr
(
expression
,
"type"
):
self
.
type
=
expression
.
type
type
=
getattr
(
expression
,
"type"
,
None
)
if
type
:
self
.
type
=
type
def
analyse_types
(
self
,
env
):
if
self
.
expression
is
not
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