Skip to content

Commit a5f64dd

Browse files
author
georg.brandl
committed
Replace PyObject_CallFunction calls with only object args
with PyObject_CallFunctionObjArgs, which is 30% faster. git-svn-id: http://svn.python.org/projects/python/trunk@46244 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 1a74594 commit a5f64dd

8 files changed

Lines changed: 17 additions & 20 deletions

File tree

Modules/cPickle.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3073,8 +3073,8 @@ find_class(PyObject *py_module_name, PyObject *py_global_name, PyObject *fc)
30733073
"pickles are not supported.");
30743074
return NULL;
30753075
}
3076-
return PyObject_CallFunction(fc, "OO", py_module_name,
3077-
py_global_name);
3076+
return PyObject_CallFunctionObjArgs(fc, py_module_name,
3077+
py_global_name, NULL);
30783078
}
30793079

30803080
module = PySys_GetObject("modules");

Modules/gcmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ handle_weakrefs(PyGC_Head *unreachable, PyGC_Head *old)
603603
assert(callback != NULL);
604604

605605
/* copy-paste of weakrefobject.c's handle_callback() */
606-
temp = PyObject_CallFunction(callback, "O", wr);
606+
temp = PyObject_CallFunctionObjArgs(callback, wr, NULL);
607607
if (temp == NULL)
608608
PyErr_WriteUnraisable(callback);
609609
else

Modules/parsermodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3267,8 +3267,8 @@ initparser(void)
32673267
&& (pickler != NULL)) {
32683268
PyObject *res;
32693269

3270-
res = PyObject_CallFunction(func, "OOO", &PyST_Type, pickler,
3271-
pickle_constructor);
3270+
res = PyObject_CallFunctionObjArgs(func, &PyST_Type, pickler,
3271+
pickle_constructor, NULL);
32723272
Py_XDECREF(res);
32733273
}
32743274
Py_XDECREF(func);

Objects/classobject.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,9 @@ PyClass_New(PyObject *bases, PyObject *dict, PyObject *name)
8181
if (!PyClass_Check(base)) {
8282
if (PyCallable_Check(
8383
(PyObject *) base->ob_type))
84-
return PyObject_CallFunction(
84+
return PyObject_CallFunctionObjArgs(
8585
(PyObject *) base->ob_type,
86-
"OOO",
87-
name,
88-
bases,
89-
dict);
86+
name, bases, dict, NULL);
9087
PyErr_SetString(PyExc_TypeError,
9188
"PyClass_New: base must be a class");
9289
return NULL;

Objects/typeobject.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4641,10 +4641,10 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name)
46414641
(void *)PyObject_GenericGetAttr))
46424642
res = PyObject_GenericGetAttr(self, name);
46434643
else
4644-
res = PyObject_CallFunction(getattribute, "OO", self, name);
4644+
res = PyObject_CallFunctionObjArgs(getattribute, self, name, NULL);
46454645
if (res == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {
46464646
PyErr_Clear();
4647-
res = PyObject_CallFunction(getattr, "OO", self, name);
4647+
res = PyObject_CallFunctionObjArgs(getattr, self, name, NULL);
46484648
}
46494649
return res;
46504650
}
@@ -4781,7 +4781,7 @@ slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type)
47814781
obj = Py_None;
47824782
if (type == NULL)
47834783
type = Py_None;
4784-
return PyObject_CallFunction(get, "OOO", self, obj, type);
4784+
return PyObject_CallFunctionObjArgs(get, self, obj, type, NULL);
47854785
}
47864786

47874787
static int
@@ -5728,8 +5728,8 @@ super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
57285728
if (su->ob_type != &PySuper_Type)
57295729
/* If su is an instance of a (strict) subclass of super,
57305730
call its type */
5731-
return PyObject_CallFunction((PyObject *)su->ob_type,
5732-
"OO", su->type, obj);
5731+
return PyObject_CallFunctionObjArgs((PyObject *)su->ob_type,
5732+
su->type, obj, NULL);
57335733
else {
57345734
/* Inline the common case */
57355735
PyTypeObject *obj_type = supercheck(su->type, obj);

Objects/weakrefobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ PyWeakref_GetObject(PyObject *ref)
851851
static void
852852
handle_callback(PyWeakReference *ref, PyObject *callback)
853853
{
854-
PyObject *cbresult = PyObject_CallFunction(callback, "O", ref);
854+
PyObject *cbresult = PyObject_CallFunctionObjArgs(callback, ref, NULL);
855855

856856
if (cbresult == NULL)
857857
PyErr_WriteUnraisable(callback);

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4053,7 +4053,7 @@ build_class(PyObject *methods, PyObject *bases, PyObject *name)
40534053
metaclass = (PyObject *) &PyClass_Type;
40544054
Py_INCREF(metaclass);
40554055
}
4056-
result = PyObject_CallFunction(metaclass, "OOO", name, bases, methods);
4056+
result = PyObject_CallFunctionObjArgs(metaclass, name, bases, methods, NULL);
40574057
Py_DECREF(metaclass);
40584058
if (result == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {
40594059
/* A type error here likely means that the user passed

Python/import.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ get_path_importer(PyObject *path_importer_cache, PyObject *path_hooks,
10431043
PyObject *hook = PyList_GetItem(path_hooks, j);
10441044
if (hook == NULL)
10451045
return NULL;
1046-
importer = PyObject_CallFunction(hook, "O", p);
1046+
importer = PyObject_CallFunctionObjArgs(hook, p, NULL);
10471047
if (importer != NULL)
10481048
break;
10491049

@@ -2499,8 +2499,8 @@ PyImport_Import(PyObject *module_name)
24992499
goto err;
25002500

25012501
/* Call the _import__ function with the proper argument list */
2502-
r = PyObject_CallFunction(import, "OOOO",
2503-
module_name, globals, globals, silly_list);
2502+
r = PyObject_CallFunctionObjArgs(import, module_name, globals,
2503+
globals, silly_list, NULL);
25042504

25052505
err:
25062506
Py_XDECREF(globals);

0 commit comments

Comments
 (0)