Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df142fd

Browse files
committed
import_name() now uses fast call
Issue #27128: import_name() now calls _PyObject_FastCall() to avoid the creation of a temporary tuple.
1 parent 9def090 commit df142fd

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

Python/ceval.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5247,7 +5247,8 @@ static PyObject *
52475247
import_name(PyFrameObject *f, PyObject *name, PyObject *fromlist, PyObject *level)
52485248
{
52495249
_Py_IDENTIFIER(__import__);
5250-
PyObject *import_func, *args, *res;
5250+
PyObject *import_func, *res;
5251+
PyObject* stack[5];
52515252

52525253
import_func = _PyDict_GetItemId(f->f_builtins, &PyId___import__);
52535254
if (import_func == NULL) {
@@ -5271,18 +5272,13 @@ import_name(PyFrameObject *f, PyObject *name, PyObject *fromlist, PyObject *leve
52715272
}
52725273

52735274
Py_INCREF(import_func);
5274-
args = PyTuple_Pack(5,
5275-
name,
5276-
f->f_globals,
5277-
f->f_locals == NULL ? Py_None : f->f_locals,
5278-
fromlist,
5279-
level);
5280-
if (args == NULL) {
5281-
Py_DECREF(import_func);
5282-
return NULL;
5283-
}
5284-
res = PyEval_CallObject(import_func, args);
5285-
Py_DECREF(args);
5275+
5276+
stack[0] = name;
5277+
stack[1] = f->f_globals;
5278+
stack[2] = f->f_locals == NULL ? Py_None : f->f_locals;
5279+
stack[3] = fromlist;
5280+
stack[4] = level;
5281+
res = _PyObject_FastCall(import_func, stack, 5, NULL);
52865282
Py_DECREF(import_func);
52875283
return res;
52885284
}

0 commit comments

Comments
 (0)