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

Skip to content

Commit 9cd0efc

Browse files
committed
Use PyDict_Copy() and PyDict_Update() instead of using PyObject_CallMethod()
to call the corresponding methods. This is not a performance improvement since the times are still swamped by disk I/O, but cleans up the code just a little.
1 parent 61f7949 commit 9cd0efc

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

Python/import.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ _PyImport_FixupExtension(char *name, char *filename)
392392
dict = PyModule_GetDict(mod);
393393
if (dict == NULL)
394394
return NULL;
395-
copy = PyObject_CallMethod(dict, "copy", "");
395+
copy = PyDict_Copy(dict);
396396
if (copy == NULL)
397397
return NULL;
398398
PyDict_SetItemString(extensions, filename, copy);
@@ -403,7 +403,7 @@ _PyImport_FixupExtension(char *name, char *filename)
403403
PyObject *
404404
_PyImport_FindExtension(char *name, char *filename)
405405
{
406-
PyObject *dict, *mod, *mdict, *result;
406+
PyObject *dict, *mod, *mdict;
407407
if (extensions == NULL)
408408
return NULL;
409409
dict = PyDict_GetItemString(extensions, filename);
@@ -415,10 +415,8 @@ _PyImport_FindExtension(char *name, char *filename)
415415
mdict = PyModule_GetDict(mod);
416416
if (mdict == NULL)
417417
return NULL;
418-
result = PyObject_CallMethod(mdict, "update", "O", dict);
419-
if (result == NULL)
418+
if (PyDict_Update(mdict, dict))
420419
return NULL;
421-
Py_DECREF(result);
422420
if (Py_VerboseFlag)
423421
PySys_WriteStderr("import %s # previously loaded (%s)\n",
424422
name, filename);

0 commit comments

Comments
 (0)