Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5e02c782
Commit
5e02c782
authored
Sep 21, 2017
by
Serhiy Storchaka
Committed by
GitHub
Sep 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-31410: Optimized calling wrapper and classmethod descriptors. (#3481)
parent
b3a77964
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
29 deletions
+34
-29
Misc/NEWS.d/next/Core and Builtins/2017-09-10-20-58-51.bpo-31410.wD_RbH.rst
...ore and Builtins/2017-09-10-20-58-51.bpo-31410.wD_RbH.rst
+1
-0
Objects/descrobject.c
Objects/descrobject.c
+33
-29
No files found.
Misc/NEWS.d/next/Core and Builtins/2017-09-10-20-58-51.bpo-31410.wD_RbH.rst
0 → 100644
View file @
5e02c782
Optimized calling wrapper and classmethod descriptors.
Objects/descrobject.c
View file @
5e02c782
...
...
@@ -296,7 +296,7 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args,
PyObject
*
kwds
)
{
Py_ssize_t
argc
;
PyObject
*
self
,
*
func
,
*
result
,
**
stack
;
PyObject
*
self
,
*
result
;
/* Make sure that the first argument is acceptable as 'self' */
assert
(
PyTuple_Check
(
args
));
...
...
@@ -330,20 +330,38 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args,
return
NULL
;
}
func
=
PyCFunction_NewEx
(
descr
->
d_method
,
self
,
NULL
);
if
(
func
==
NULL
)
return
NULL
;
stack
=
&
PyTuple_GET_ITEM
(
args
,
1
);
result
=
_PyObject_FastCallDict
(
func
,
stack
,
argc
-
1
,
kwds
);
Py_DECREF
(
func
);
result
=
_PyMethodDef_RawFastCallDict
(
descr
->
d_method
,
self
,
&
PyTuple_GET_ITEM
(
args
,
1
),
argc
-
1
,
kwds
);
result
=
_Py_CheckFunctionResult
((
PyObject
*
)
descr
,
result
,
NULL
);
return
result
;
}
Py_LOCAL_INLINE
(
PyObject
*
)
wrapperdescr_raw_call
(
PyWrapperDescrObject
*
descr
,
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
wrapperfunc
wrapper
=
descr
->
d_base
->
wrapper
;
if
(
descr
->
d_base
->
flags
&
PyWrapperFlag_KEYWORDS
)
{
wrapperfunc_kwds
wk
=
(
wrapperfunc_kwds
)
wrapper
;
return
(
*
wk
)(
self
,
args
,
descr
->
d_wrapped
,
kwds
);
}
if
(
kwds
!=
NULL
&&
(
!
PyDict_Check
(
kwds
)
||
PyDict_GET_SIZE
(
kwds
)
!=
0
))
{
PyErr_Format
(
PyExc_TypeError
,
"wrapper %s() takes no keyword arguments"
,
descr
->
d_base
->
name
);
return
NULL
;
}
return
(
*
wrapper
)(
self
,
args
,
descr
->
d_wrapped
);
}
static
PyObject
*
wrapperdescr_call
(
PyWrapperDescrObject
*
descr
,
PyObject
*
args
,
PyObject
*
kwds
)
{
Py_ssize_t
argc
;
PyObject
*
self
,
*
func
,
*
result
,
**
stack
;
PyObject
*
self
,
*
result
;
/* Make sure that the first argument is acceptable as 'self' */
assert
(
PyTuple_Check
(
args
));
...
...
@@ -369,16 +387,16 @@ wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds)
return
NULL
;
}
func
=
PyWrapper_New
((
PyObject
*
)
descr
,
self
);
if
(
func
==
NULL
)
args
=
PyTuple_GetSlice
(
args
,
1
,
argc
);
if
(
args
==
NULL
)
{
return
NULL
;
stack
=
&
PyTuple_GET_ITEM
(
args
,
1
);
result
=
_PyObject_FastCallDict
(
func
,
stack
,
argc
-
1
,
kwds
);
Py_DECREF
(
func
);
}
result
=
wrapperdescr_raw_call
(
descr
,
self
,
args
,
kwds
);
Py_DECREF
(
args
);
return
result
;
}
static
PyObject
*
method_get_doc
(
PyMethodDescrObject
*
descr
,
void
*
closure
)
{
...
...
@@ -1167,21 +1185,7 @@ static PyGetSetDef wrapper_getsets[] = {
static
PyObject
*
wrapper_call
(
wrapperobject
*
wp
,
PyObject
*
args
,
PyObject
*
kwds
)
{
wrapperfunc
wrapper
=
wp
->
descr
->
d_base
->
wrapper
;
PyObject
*
self
=
wp
->
self
;
if
(
wp
->
descr
->
d_base
->
flags
&
PyWrapperFlag_KEYWORDS
)
{
wrapperfunc_kwds
wk
=
(
wrapperfunc_kwds
)
wrapper
;
return
(
*
wk
)(
self
,
args
,
wp
->
descr
->
d_wrapped
,
kwds
);
}
if
(
kwds
!=
NULL
&&
(
!
PyDict_Check
(
kwds
)
||
PyDict_GET_SIZE
(
kwds
)
!=
0
))
{
PyErr_Format
(
PyExc_TypeError
,
"wrapper %s() takes no keyword arguments"
,
wp
->
descr
->
d_base
->
name
);
return
NULL
;
}
return
(
*
wrapper
)(
self
,
args
,
wp
->
descr
->
d_wrapped
);
return
wrapperdescr_raw_call
(
wp
->
descr
,
wp
->
self
,
args
,
kwds
);
}
static
int
...
...
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