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
61ab9c73
Commit
61ab9c73
authored
Feb 16, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reduce attribute lookup overhead a bit
parent
c4bf2bc5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
7 deletions
+34
-7
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+3
-1
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+10
-4
Cython/Utility/ObjectHandling.c
Cython/Utility/ObjectHandling.c
+19
-1
Cython/Utility/Optimize.c
Cython/Utility/Optimize.c
+2
-1
No files found.
Cython/Compiler/ExprNodes.py
View file @
61ab9c73
...
@@ -4958,8 +4958,10 @@ class AttributeNode(ExprNode):
...
@@ -4958,8 +4958,10 @@ class AttributeNode(ExprNode):
def
generate_result_code
(
self
,
code
):
def
generate_result_code
(
self
,
code
):
if
self
.
is_py_attr
:
if
self
.
is_py_attr
:
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"PyObjectGetAttrStr"
,
"ObjectHandling.c"
))
code
.
putln
(
code
.
putln
(
'%s =
PyObject_GetAt
tr(%s, %s); %s'
%
(
'%s =
__Pyx_PyObject_GetAttrS
tr(%s, %s); %s'
%
(
self
.
result
(),
self
.
result
(),
self
.
obj
.
py_result
(),
self
.
obj
.
py_result
(),
code
.
intern_identifier
(
self
.
attribute
),
code
.
intern_identifier
(
self
.
attribute
),
...
...
Cython/Compiler/Nodes.py
View file @
61ab9c73
...
@@ -3856,8 +3856,10 @@ class OverrideCheckNode(StatNode):
...
@@ -3856,8 +3856,10 @@ class OverrideCheckNode(StatNode):
func_node_temp
=
code
.
funcstate
.
allocate_temp
(
py_object_type
,
manage_ref
=
True
)
func_node_temp
=
code
.
funcstate
.
allocate_temp
(
py_object_type
,
manage_ref
=
True
)
self
.
func_node
.
set_cname
(
func_node_temp
)
self
.
func_node
.
set_cname
(
func_node_temp
)
# need to get attribute manually--scope would return cdef method
# need to get attribute manually--scope would return cdef method
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"PyObjectGetAttrStr"
,
"ObjectHandling.c"
))
err
=
code
.
error_goto_if_null
(
func_node_temp
,
self
.
pos
)
err
=
code
.
error_goto_if_null
(
func_node_temp
,
self
.
pos
)
code
.
putln
(
"%s =
PyObject_GetAt
tr(%s, %s); %s"
%
(
code
.
putln
(
"%s =
__Pyx_PyObject_GetAttrS
tr(%s, %s); %s"
%
(
func_node_temp
,
self_arg
,
interned_attr_cname
,
err
))
func_node_temp
,
self_arg
,
interned_attr_cname
,
err
))
code
.
put_gotref
(
func_node_temp
)
code
.
put_gotref
(
func_node_temp
)
is_builtin_function_or_method
=
"PyCFunction_Check(%s)"
%
func_node_temp
is_builtin_function_or_method
=
"PyCFunction_Check(%s)"
%
func_node_temp
...
@@ -5849,10 +5851,12 @@ class WithStatNode(StatNode):
...
@@ -5849,10 +5851,12 @@ class WithStatNode(StatNode):
code
.
putln
(
"/*with:*/ {"
)
code
.
putln
(
"/*with:*/ {"
)
self
.
manager
.
generate_evaluation_code
(
code
)
self
.
manager
.
generate_evaluation_code
(
code
)
self
.
exit_var
=
code
.
funcstate
.
allocate_temp
(
py_object_type
,
manage_ref
=
False
)
self
.
exit_var
=
code
.
funcstate
.
allocate_temp
(
py_object_type
,
manage_ref
=
False
)
code
.
putln
(
"%s = PyObject_GetAttr(%s, %s); %s"
%
(
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"PyObjectGetAttrStr"
,
"ObjectHandling.c"
))
code
.
putln
(
"%s = __Pyx_PyObject_GetAttrStr(%s, %s); %s"
%
(
self
.
exit_var
,
self
.
exit_var
,
self
.
manager
.
py_result
(),
self
.
manager
.
py_result
(),
code
.
get_py_string_const
(
EncodedString
(
'__exit__'
),
identifier
=
True
),
code
.
intern_identifier
(
EncodedString
(
'__exit__'
)
),
code
.
error_goto_if_null
(
self
.
exit_var
,
self
.
pos
),
code
.
error_goto_if_null
(
self
.
exit_var
,
self
.
pos
),
))
))
code
.
put_gotref
(
self
.
exit_var
)
code
.
put_gotref
(
self
.
exit_var
)
...
@@ -6710,10 +6714,12 @@ class FromImportStatNode(StatNode):
...
@@ -6710,10 +6714,12 @@ class FromImportStatNode(StatNode):
code
.
error_goto
(
self
.
pos
)))
code
.
error_goto
(
self
.
pos
)))
item_temp
=
code
.
funcstate
.
allocate_temp
(
py_object_type
,
manage_ref
=
True
)
item_temp
=
code
.
funcstate
.
allocate_temp
(
py_object_type
,
manage_ref
=
True
)
self
.
item
.
set_cname
(
item_temp
)
self
.
item
.
set_cname
(
item_temp
)
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"PyObjectGetAttrStr"
,
"ObjectHandling.c"
))
for
name
,
target
,
coerced_item
in
self
.
interned_items
:
for
name
,
target
,
coerced_item
in
self
.
interned_items
:
cname
=
code
.
intern_identifier
(
name
)
cname
=
code
.
intern_identifier
(
name
)
code
.
putln
(
code
.
putln
(
'%s =
PyObject_GetAt
tr(%s, %s);'
%
(
'%s =
__Pyx_PyObject_GetAttrS
tr(%s, %s);'
%
(
item_temp
,
item_temp
,
self
.
module
.
py_result
(),
self
.
module
.
py_result
(),
cname
))
cname
))
...
...
Cython/Utility/ObjectHandling.c
View file @
61ab9c73
...
@@ -586,13 +586,31 @@ static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) {
...
@@ -586,13 +586,31 @@ static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) {
return
unlikely
(
b
<
0
)
?
NULL
:
__Pyx_PyBool_FromLong
(
b
);
return
unlikely
(
b
<
0
)
?
NULL
:
__Pyx_PyBool_FromLong
(
b
);
}
}
/////////////// PyObjectGetAttrStr.proto ///////////////
#if CYTHON_COMPILING_IN_CPYTHON
static
CYTHON_INLINE
PyObject
*
__Pyx_PyObject_GetAttrStr
(
PyObject
*
obj
,
PyObject
*
attr_name
)
{
PyTypeObject
*
tp
=
Py_TYPE
(
obj
);
if
(
likely
(
tp
->
tp_getattro
))
return
tp
->
tp_getattro
(
obj
,
attr_name
);
#if PY_MAJOR_VERSION < 3
if
(
likely
(
tp
->
tp_getattr
))
return
tp
->
tp_getattr
(
obj
,
PyString_AS_STRING
(
attr_name
));
#endif
return
PyObject_GetAttr
(
obj
,
attr_name
);
}
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif
/////////////// PyObjectCallMethod.proto ///////////////
/////////////// PyObjectCallMethod.proto ///////////////
//@requires: PyObjectGetAttrStr
//@substitute: naming
//@substitute: naming
static
PyObject
*
__Pyx_PyObject_CallMethodTuple
(
PyObject
*
obj
,
PyObject
*
method_name
,
PyObject
*
args
)
{
static
PyObject
*
__Pyx_PyObject_CallMethodTuple
(
PyObject
*
obj
,
PyObject
*
method_name
,
PyObject
*
args
)
{
PyObject
*
method
,
*
result
=
NULL
;
PyObject
*
method
,
*
result
=
NULL
;
if
(
unlikely
(
!
args
))
return
NULL
;
if
(
unlikely
(
!
args
))
return
NULL
;
method
=
PyObject_GetAt
tr
(
obj
,
method_name
);
method
=
__Pyx_PyObject_GetAttrS
tr
(
obj
,
method_name
);
if
(
unlikely
(
!
method
))
goto
bad
;
if
(
unlikely
(
!
method
))
goto
bad
;
result
=
PyObject_Call
(
method
,
args
,
NULL
);
result
=
PyObject_Call
(
method
,
args
,
NULL
);
Py_DECREF
(
method
);
Py_DECREF
(
method
);
...
...
Cython/Utility/Optimize.c
View file @
61ab9c73
...
@@ -82,6 +82,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L) {
...
@@ -82,6 +82,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L) {
static
PyObject
*
__Pyx_PyObject_PopIndex
(
PyObject
*
L
,
Py_ssize_t
ix
);
/*proto*/
static
PyObject
*
__Pyx_PyObject_PopIndex
(
PyObject
*
L
,
Py_ssize_t
ix
);
/*proto*/
/////////////// pop_index ///////////////
/////////////// pop_index ///////////////
//@requires: ObjectHandling.c::PyObjectGetAttrStr
static
PyObject
*
__Pyx_PyObject_PopIndex
(
PyObject
*
L
,
Py_ssize_t
ix
)
{
static
PyObject
*
__Pyx_PyObject_PopIndex
(
PyObject
*
L
,
Py_ssize_t
ix
)
{
PyObject
*
r
,
*
m
,
*
t
,
*
py_ix
;
PyObject
*
r
,
*
m
,
*
t
,
*
py_ix
;
...
@@ -103,7 +104,7 @@ static PyObject* __Pyx_PyObject_PopIndex(PyObject* L, Py_ssize_t ix) {
...
@@ -103,7 +104,7 @@ static PyObject* __Pyx_PyObject_PopIndex(PyObject* L, Py_ssize_t ix) {
}
}
#endif
#endif
py_ix
=
t
=
NULL
;
py_ix
=
t
=
NULL
;
m
=
PyObject_GetAt
tr
(
L
,
PYIDENT
(
"pop"
));
m
=
__Pyx_PyObject_GetAttrS
tr
(
L
,
PYIDENT
(
"pop"
));
if
(
!
m
)
goto
bad
;
if
(
!
m
)
goto
bad
;
py_ix
=
PyInt_FromSsize_t
(
ix
);
py_ix
=
PyInt_FromSsize_t
(
ix
);
if
(
!
py_ix
)
goto
bad
;
if
(
!
py_ix
)
goto
bad
;
...
...
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