Skip to content

Commit 4cc6905

Browse files
committed
PeRfoRManCe
1 parent 4cd4322 commit 4cc6905

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Python/import.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "Python.h"
44
#include "pycore_audit.h" // _PySys_Audit()
55
#include "pycore_ceval.h"
6+
#include "pycore_dict.h" // _PyDict_Contains_KnownHash()
67
#include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION()
78
#include "pycore_hashtable.h" // _Py_hashtable_new_full()
89
#include "pycore_import.h" // _PyImport_BootstrapImp()
@@ -3822,7 +3823,8 @@ _PyImport_LoadLazyImportTstate(PyThreadState *tstate, PyObject *lazy_import)
38223823
}
38233824
}
38243825

3825-
int is_loading = PySet_Contains(importing, lazy_import);
3826+
assert(PyAnySet_CheckExact(importing));
3827+
int is_loading = _PySet_Contains((PySetObject *)importing, lazy_import);
38263828
if (is_loading < 0) {
38273829
_PyImport_ReleaseLock(interp);
38283830
return NULL;
@@ -4215,7 +4217,7 @@ static PyObject *
42154217
get_mod_dict(PyObject *module)
42164218
{
42174219
if (PyModule_Check(module)) {
4218-
return Py_XNewRef(PyModule_GetDict(module));
4220+
return Py_NewRef(_PyModule_GetDict(module));
42194221
}
42204222

42214223
return PyObject_GetAttr(module, &_Py_ID(__dict__));
@@ -4291,6 +4293,7 @@ register_lazy_on_parent(PyThreadState *tstate, PyObject *name, PyObject *builtin
42914293
goto done;
42924294
}
42934295
}
4296+
assert(PyAnySet_CheckExact(lazy_submodules));
42944297
if (PySet_Add(lazy_submodules, child) < 0) {
42954298
Py_DECREF(lazy_submodules);
42964299
goto done;
@@ -4387,6 +4390,7 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
43874390
// Add the module name to sys.lazy_modules set (PEP 810)
43884391
PyObject *lazy_modules_set = interp->imports.lazy_modules_set;
43894392
if (lazy_modules_set != NULL) {
4393+
assert(PyAnySet_CheckExact(lazy_modules_set));
43904394
if (PySet_Add(lazy_modules_set, abs_name) < 0) {
43914395
Py_DECREF(res);
43924396
Py_DECREF(abs_name);
@@ -5418,11 +5422,12 @@ _imp__set_lazy_attributes_impl(PyObject *module, PyObject *child_module,
54185422
if (child_dict == NULL || !PyDict_CheckExact(child_dict)) {
54195423
goto done;
54205424
}
5425+
assert(PyAnySet_CheckExact(lazy_submodules));
54215426
PyObject *attr_name;
54225427
Py_ssize_t pos = 0;
54235428
Py_hash_t hash;
54245429
while (_PySet_NextEntry(lazy_submodules, &pos, &attr_name, &hash)) {
5425-
if (PyDict_Contains(child_dict, attr_name)) {
5430+
if (_PyDict_Contains_KnownHash(child_dict, attr_name, hash)) {
54265431
continue;
54275432
}
54285433
PyObject *builtins = _PyEval_GetBuiltins(tstate);

0 commit comments

Comments
 (0)