Keyboard Shortcuts

File
u :up to issue
m :publish + mail comments
M :edit review message
j / k :jump to file after / before current file
J / K :jump to next file with a comment after / before current file
Side-by-side diff
i :toggle intra-line diffs
e :expand all comments
c :collapse all comments
s :toggle showing all comments
n / p :next / previous diff chunk or comment
N / P :next / previous comment
<Up> / <Down> :next / previous line
<Enter> :respond to / edit current comment
d :mark current comment as done
Issue
u :up to list of issues
m :publish + mail comments
j / k :jump to patch after / before current patch
o / <Enter> :open current patch in side-by-side view
i :open current patch in unified diff view
Issue List
j / k :jump to issue after / before current issue
o / <Enter> :open current issue
# : close issue
Comment/message editing
<Ctrl> + s or <Ctrl> + Enter :save comment
<Esc> :cancel edit
Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(109)
Issues Repositories Search
Open Issues | Closed Issues | All Issues | Sign in with your Google Account to create issues and add comments

Unified Diff: Modules/_lsprof.c

Issue 160063: LOAD_METHOD/CALL_METHOD: Avoid allocating bound methods when possible (Closed)
Patch Set: Merge w/ trunk, fix test_profile Created 15 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/test/test_llvm.py ('k') | Objects/classobject.c » ('j') | no next file with comments »
('e') | ('c') | ('s')
Index: Modules/_lsprof.c
===================================================================
--- Modules/_lsprof.c (revision 1167)
+++ Modules/_lsprof.c (working copy)
@@ -165,17 +165,12 @@
static PyObject *
normalizeUserObj(PyObject *obj)
{
- PyCFunctionObject *fn;
- if (!PyCFunction_Check(obj)) {
- Py_INCREF(obj);
- return obj;
- }
/* Replace built-in function objects with a descriptive string
because of built-in methods -- keeping a reference to
__self__ is probably not a good idea. */
- fn = (PyCFunctionObject *)obj;
+ PyCFunctionObject *fn = (PyCFunctionObject *)obj;
- if (fn->m_self == NULL) {
+ if (PyCFunction_Check(obj) && fn->m_self == NULL) {
/* built-in function: look up the module name */
PyObject *mod = fn->m_module;
char *modname;
@@ -200,16 +195,27 @@
return PyString_FromFormat("<%s>",
fn->m_ml->ml_name);
}
- else {
+ else if (PyCFunction_Check(obj) || PyMethodDescr_Check(obj)) {
/* built-in method: try to return
repr(getattr(type(__self__), __name__))
*/
- PyObject *self = fn->m_self;
- PyObject *name = PyString_FromString(fn->m_ml->ml_name);
- if (name != NULL) {
- PyObject *mo = _PyType_Lookup(Py_TYPE(self), name);
+ PyTypeObject *type;
+ const char *name;
+ PyObject *name_obj;
+ if (PyCFunction_Check(obj)) {
+ type = Py_TYPE(fn->m_self);
+ name = fn->m_ml->ml_name;
+ }
+ else {
+ PyMethodDescrObject *descr = (PyMethodDescrObject *)obj;
+ type = descr->d_type;
+ name = descr->d_method->ml_name;
+ }
+ name_obj = PyString_FromString(name);
+ if (name_obj != NULL) {
+ PyObject *mo = _PyType_Lookup(type, name_obj);
Py_XINCREF(mo);
- Py_DECREF(name);
+ Py_DECREF(name_obj);
if (mo != NULL) {
PyObject *res = PyObject_Repr(mo);
Py_DECREF(mo);
@@ -218,9 +224,12 @@
}
}
PyErr_Clear();
- return PyString_FromFormat("<built-in method %s>",
- fn->m_ml->ml_name);
+ return PyString_FromFormat("<built-in method %s>", name);
}
+ else {
+ Py_INCREF(obj);
+ return obj;
+ }
}
static ProfilerEntry*
@@ -454,11 +463,15 @@
/* the Python function 'frame' is issuing a call to the built-in
function 'arg' */
case PyTrace_C_CALL:
- if ((((ProfilerObject *)self)->flags & POF_BUILTINS)
- && PyCFunction_Check(arg)) {
- ptrace_enter_call(self,
- ((PyCFunctionObject *)arg)->m_ml,
- arg);
+ if (((ProfilerObject *)self)->flags & POF_BUILTINS) {
+ PyMethodDef *ml = NULL;
+ if (PyCFunction_Check(arg)) {
+ ml = ((PyCFunctionObject *)arg)->m_ml;
+ }
+ else if (PyMethodDescr_Check(arg)) {
+ ml = ((PyMethodDescrObject*)arg)->d_method;
+ }
+ ptrace_enter_call(self, ml, arg);
}
break;
@@ -466,10 +479,15 @@
caller 'frame' */
case PyTrace_C_RETURN: /* ...normally */
case PyTrace_C_EXCEPTION: /* ...with an exception set */
- if ((((ProfilerObject *)self)->flags & POF_BUILTINS)
- && PyCFunction_Check(arg)) {
- ptrace_leave_call(self,
- ((PyCFunctionObject *)arg)->m_ml);
+ if (((ProfilerObject *)self)->flags & POF_BUILTINS) {
+ PyMethodDef *ml = NULL;
+ if (PyCFunction_Check(arg)) {
+ ml = ((PyCFunctionObject *)arg)->m_ml;
+ }
+ else if (PyMethodDescr_Check(arg)) {
+ ml = ((PyMethodDescrObject*)arg)->d_method;
+ }
+ ptrace_leave_call(self, ml);
}
break;
#endif
« no previous file with comments | « Lib/test/test_llvm.py ('k') | Objects/classobject.c » ('j') | no next file with comments »
Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b

AltStyle によって変換されたページ (->オリジナル) /