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
a6a2d569
Commit
a6a2d569
authored
Jul 03, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
faster call to builtin type()
parent
44b50ac1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
1 deletion
+28
-1
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+28
-1
No files found.
Cython/Compiler/Optimize.py
View file @
a6a2d569
...
@@ -690,7 +690,6 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform):
...
@@ -690,7 +690,6 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform):
])
])
def
_handle_simple_function_getattr
(
self
,
node
,
pos_args
):
def
_handle_simple_function_getattr
(
self
,
node
,
pos_args
):
# not really a builtin *type*, but worth optimising anyway
args
=
pos_args
.
args
args
=
pos_args
.
args
if
len
(
args
)
==
2
:
if
len
(
args
)
==
2
:
node
=
ExprNodes
.
PythonCapiCallNode
(
node
=
ExprNodes
.
PythonCapiCallNode
(
...
@@ -710,6 +709,23 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform):
...
@@ -710,6 +709,23 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform):
"expected 2 or 3, found %d"
%
len
(
args
))
"expected 2 or 3, found %d"
%
len
(
args
))
return
node
return
node
Pyx_Type_func_type
=
PyrexTypes
.
CFuncType
(
Builtin
.
type_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"object"
,
PyrexTypes
.
py_object_type
,
None
)
])
def
_handle_simple_function_type
(
self
,
node
,
pos_args
):
args
=
pos_args
.
args
if
len
(
args
)
!=
1
:
return
node
node
=
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
"__Pyx_Type"
,
self
.
Pyx_Type_func_type
,
args
=
args
,
is_temp
=
node
.
is_temp
,
utility_code
=
pytype_utility_code
,
)
return
node
### methods of builtin types
### methods of builtin types
PyObject_Append_func_type
=
PyrexTypes
.
CFuncType
(
PyObject_Append_func_type
=
PyrexTypes
.
CFuncType
(
...
@@ -813,6 +829,17 @@ impl = ""
...
@@ -813,6 +829,17 @@ impl = ""
)
)
pytype_utility_code
=
UtilityCode
(
proto
=
"""
static INLINE PyObject* __Pyx_Type(PyObject* o) {
PyObject* type = (PyObject*) Py_TYPE(o);
Py_INCREF(type);
return type;
}
"""
)
class
ConstantFolding
(
Visitor
.
VisitorTransform
,
SkipDeclarations
):
class
ConstantFolding
(
Visitor
.
VisitorTransform
,
SkipDeclarations
):
"""Calculate the result of constant expressions to store it in
"""Calculate the result of constant expressions to store it in
``expr_node.constant_result``, and replace trivial cases by their
``expr_node.constant_result``, and replace trivial cases by their
...
...
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