mirror of
https://github.com/python/cpython.git
synced 2025-10-03 21:55:41 +00:00
import_name() now uses fast call
Issue #27128: import_name() now calls _PyObject_FastCall() to avoid the creation of a temporary tuple.
This commit is contained in:
parent
9def0901e2
commit
df142fdc4b
1 changed files with 9 additions and 13 deletions
|
@ -5247,7 +5247,8 @@ static PyObject *
|
||||||
import_name(PyFrameObject *f, PyObject *name, PyObject *fromlist, PyObject *level)
|
import_name(PyFrameObject *f, PyObject *name, PyObject *fromlist, PyObject *level)
|
||||||
{
|
{
|
||||||
_Py_IDENTIFIER(__import__);
|
_Py_IDENTIFIER(__import__);
|
||||||
PyObject *import_func, *args, *res;
|
PyObject *import_func, *res;
|
||||||
|
PyObject* stack[5];
|
||||||
|
|
||||||
import_func = _PyDict_GetItemId(f->f_builtins, &PyId___import__);
|
import_func = _PyDict_GetItemId(f->f_builtins, &PyId___import__);
|
||||||
if (import_func == NULL) {
|
if (import_func == NULL) {
|
||||||
|
@ -5271,18 +5272,13 @@ import_name(PyFrameObject *f, PyObject *name, PyObject *fromlist, PyObject *leve
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(import_func);
|
Py_INCREF(import_func);
|
||||||
args = PyTuple_Pack(5,
|
|
||||||
name,
|
stack[0] = name;
|
||||||
f->f_globals,
|
stack[1] = f->f_globals;
|
||||||
f->f_locals == NULL ? Py_None : f->f_locals,
|
stack[2] = f->f_locals == NULL ? Py_None : f->f_locals;
|
||||||
fromlist,
|
stack[3] = fromlist;
|
||||||
level);
|
stack[4] = level;
|
||||||
if (args == NULL) {
|
res = _PyObject_FastCall(import_func, stack, 5, NULL);
|
||||||
Py_DECREF(import_func);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
res = PyEval_CallObject(import_func, args);
|
|
||||||
Py_DECREF(args);
|
|
||||||
Py_DECREF(import_func);
|
Py_DECREF(import_func);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue