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
53eb0a27
Commit
53eb0a27
authored
May 21, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extend unbound builtin method call optimisation to varargs functions
parent
9ba3f98b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
13 deletions
+32
-13
Cython/Utility/ObjectHandling.c
Cython/Utility/ObjectHandling.c
+32
-13
No files found.
Cython/Utility/ObjectHandling.c
View file @
53eb0a27
...
@@ -1121,14 +1121,15 @@ static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
...
@@ -1121,14 +1121,15 @@ static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
return
-
1
;
return
-
1
;
target
->
method
=
method
;
target
->
method
=
method
;
#if CYTHON_COMPILING_IN_CPYTHON
#if CYTHON_COMPILING_IN_CPYTHON
assert
(
target
->
flag
==
METH_NOARGS
||
target
->
flag
==
METH_O
);
#if PY_MAJOR_VERSION >= 3
#if PY_MAJOR_VERSION >= 3
assert
(
PyObject_TypeCheck
(
method
,
&
PyMethodDescr_Type
));
// method dscriptor type isn't exported in Py2.x, cannot easily check the type there
if
(
likely
(
PyObject_TypeCheck
(
method
,
&
PyMethodDescr_Type
)))
#endif
#endif
{
{
PyMethodDescrObject
*
descr
=
(
PyMethodDescrObject
*
)
method
;
PyMethodDescrObject
*
descr
=
(
PyMethodDescrObject
*
)
method
;
if
(
!
(
descr
->
d_method
->
ml_flags
&
(
METH_VARARGS
|
METH_KEYWORDS
))
&&
(
descr
->
d_method
->
ml_flags
&
target
->
flag
))
{
target
->
func
=
descr
->
d_method
->
ml_meth
;
target
->
func
=
descr
->
d_method
->
ml_meth
;
if
(
descr
->
d_method
->
ml_flags
&
(
METH_VARARGS
|
METH_KEYWORDS
)
||
!
(
descr
->
d_method
->
ml_flags
&
target
->
flag
))
{
target
->
flag
=
descr
->
d_method
->
ml_flags
&
(
METH_VARARGS
|
METH_KEYWORDS
|
METH_O
|
METH_NOARGS
);
}
}
}
}
#endif
#endif
...
@@ -1137,11 +1138,16 @@ static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
...
@@ -1137,11 +1138,16 @@ static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
/////////////// CallUnboundCMethod0.proto ///////////////
/////////////// CallUnboundCMethod0.proto ///////////////
//@substitute: naming
static
PyObject
*
__Pyx__CallUnboundCMethod0
(
__Pyx_CachedCFunction
*
cfunc
,
PyObject
*
self
);
/*proto*/
static
PyObject
*
__Pyx__CallUnboundCMethod0
(
__Pyx_CachedCFunction
*
cfunc
,
PyObject
*
self
);
/*proto*/
#if CYTHON_COMPILING_IN_CPYTHON
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_CallUnboundCMethod0(cfunc, self) \
#define __Pyx_CallUnboundCMethod0(cfunc, self) \
((likely((cfunc)->func)) ? (*((cfunc)->func))(self, NULL) : __Pyx__CallUnboundCMethod0(cfunc, self))
((likely((cfunc)->func)) ? \
(likely((cfunc)->flag == METH_NOARGS) ? (*((cfunc)->func))(self, NULL) : \
(likely((cfunc)->flag == (METH_VARARGS | METH_KEYWORDS)) ? ((*(PyCFunctionWithKeywords)(cfunc)->func)(self, $empty_tuple, NULL)) : \
((cfunc)->flag == METH_VARARGS ? (*((cfunc)->func))(self, $empty_tuple) : __Pyx__CallUnboundCMethod0(cfunc, self)))) : \
__Pyx__CallUnboundCMethod0(cfunc, self))
#else
#else
#define __Pyx_CallUnboundCMethod0(cfunc, self) __Pyx__CallUnboundCMethod0(cfunc, self)
#define __Pyx_CallUnboundCMethod0(cfunc, self) __Pyx__CallUnboundCMethod0(cfunc, self)
#endif
#endif
...
@@ -1175,7 +1181,8 @@ static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObje
...
@@ -1175,7 +1181,8 @@ static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObje
#if CYTHON_COMPILING_IN_CPYTHON
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_CallUnboundCMethod1(cfunc, self, arg) \
#define __Pyx_CallUnboundCMethod1(cfunc, self, arg) \
((likely((cfunc)->func)) ? (*((cfunc)->func))(self, arg) : __Pyx__CallUnboundCMethod1(cfunc, self, arg))
((likely((cfunc)->func && (cfunc)->flag == METH_O)) ? (*((cfunc)->func))(self, arg) : \
__Pyx__CallUnboundCMethod1(cfunc, self, arg))
#else
#else
#define __Pyx_CallUnboundCMethod1(cfunc, self, arg) __Pyx__CallUnboundCMethod1(cfunc, self, arg)
#define __Pyx_CallUnboundCMethod1(cfunc, self, arg) __Pyx__CallUnboundCMethod1(cfunc, self, arg)
#endif
#endif
...
@@ -1188,17 +1195,29 @@ static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObje
...
@@ -1188,17 +1195,29 @@ static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObje
PyObject
*
args
,
*
result
=
NULL
;
PyObject
*
args
,
*
result
=
NULL
;
if
(
unlikely
(
!
cfunc
->
method
)
&&
unlikely
(
__Pyx_TryUnpackUnboundCMethod
(
cfunc
)
<
0
))
return
NULL
;
if
(
unlikely
(
!
cfunc
->
method
)
&&
unlikely
(
__Pyx_TryUnpackUnboundCMethod
(
cfunc
)
<
0
))
return
NULL
;
#if CYTHON_COMPILING_IN_CPYTHON
#if CYTHON_COMPILING_IN_CPYTHON
args
=
PyTuple_New
(
2
);
if
(
cfunc
->
func
&&
(
cfunc
->
flag
&
METH_VARARGS
))
{
if
(
unlikely
(
!
args
))
goto
bad
;
args
=
PyTuple_New
(
1
);
Py_INCREF
(
self
);
if
(
unlikely
(
!
args
))
goto
bad
;
PyTuple_SET_ITEM
(
args
,
0
,
self
);
Py_INCREF
(
arg
);
Py_INCREF
(
arg
);
PyTuple_SET_ITEM
(
args
,
0
,
arg
);
PyTuple_SET_ITEM
(
args
,
1
,
arg
);
if
(
cfunc
->
flag
&
METH_KEYWORDS
)
result
=
(
*
(
PyCFunctionWithKeywords
)
cfunc
->
func
)(
self
,
args
,
NULL
);
else
result
=
(
*
cfunc
->
func
)(
self
,
args
);
}
else
{
args
=
PyTuple_New
(
2
);
if
(
unlikely
(
!
args
))
goto
bad
;
Py_INCREF
(
self
);
PyTuple_SET_ITEM
(
args
,
0
,
self
);
Py_INCREF
(
arg
);
PyTuple_SET_ITEM
(
args
,
1
,
arg
);
result
=
__Pyx_PyObject_Call
(
cfunc
->
method
,
args
,
NULL
);
}
#else
#else
args
=
PyTuple_Pack
(
2
,
self
,
arg
);
args
=
PyTuple_Pack
(
2
,
self
,
arg
);
if
(
unlikely
(
!
args
))
goto
bad
;
if
(
unlikely
(
!
args
))
goto
bad
;
#endif
result
=
__Pyx_PyObject_Call
(
cfunc
->
method
,
args
,
NULL
);
result
=
__Pyx_PyObject_Call
(
cfunc
->
method
,
args
,
NULL
);
#endif
bad:
bad:
Py_XDECREF
(
args
);
Py_XDECREF
(
args
);
return
result
;
return
result
;
...
...
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