Skip to content

Commit 5e9b898

Browse files
committed
Avoid locking for frozendict
1 parent 2601647 commit 5e9b898

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

Objects/setobject.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,9 @@ set_update_dict_lock_held(PySetObject *so, PyObject *other)
11861186
assert(PyAnyDict_CheckExact(other));
11871187

11881188
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(so);
1189-
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(other);
1189+
if (!PyFrozenDict_CheckExact(other)) {
1190+
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(other);
1191+
}
11901192

11911193
/* Do one big resize at the start, rather than
11921194
* incrementally resizing as we insert new keys. Expect
@@ -1260,13 +1262,16 @@ set_update_local(PySetObject *so, PyObject *other)
12601262
Py_END_CRITICAL_SECTION();
12611263
return rv;
12621264
}
1263-
else if (PyAnyDict_CheckExact(other)) {
1265+
else if (PyDict_CheckExact(other)) {
12641266
int rv;
12651267
Py_BEGIN_CRITICAL_SECTION(other);
12661268
rv = set_update_dict_lock_held(so, other);
12671269
Py_END_CRITICAL_SECTION();
12681270
return rv;
12691271
}
1272+
else if (PyFrozenDict_CheckExact(other)) {
1273+
return set_update_dict_lock_held(so, other);
1274+
}
12701275
return set_update_iterable_lock_held(so, other);
12711276
}
12721277

@@ -1283,13 +1288,16 @@ set_update_internal(PySetObject *so, PyObject *other)
12831288
Py_END_CRITICAL_SECTION2();
12841289
return rv;
12851290
}
1286-
else if (PyAnyDict_CheckExact(other)) {
1291+
else if (PyDict_CheckExact(other)) {
12871292
int rv;
12881293
Py_BEGIN_CRITICAL_SECTION2(so, other);
12891294
rv = set_update_dict_lock_held(so, other);
12901295
Py_END_CRITICAL_SECTION2();
12911296
return rv;
12921297
}
1298+
else if (PyFrozenDict_CheckExact(other)) {
1299+
return set_update_dict_lock_held(so, other);
1300+
}
12931301
else {
12941302
int rv;
12951303
Py_BEGIN_CRITICAL_SECTION(so);
@@ -2238,11 +2246,14 @@ set_symmetric_difference_update_impl(PySetObject *so, PyObject *other)
22382246
}
22392247

22402248
int rv;
2241-
if (PyAnyDict_CheckExact(other)) {
2249+
if (PyDict_CheckExact(other)) {
22422250
Py_BEGIN_CRITICAL_SECTION2(so, other);
22432251
rv = set_symmetric_difference_update_dict(so, other);
22442252
Py_END_CRITICAL_SECTION2();
22452253
}
2254+
else if (PyFrozenDict_CheckExact(other)) {
2255+
rv = set_symmetric_difference_update_dict(so, other);
2256+
}
22462257
else if (PyAnySet_Check(other)) {
22472258
Py_BEGIN_CRITICAL_SECTION2(so, other);
22482259
rv = set_symmetric_difference_update_set(so, (PySetObject *)other);

0 commit comments

Comments
 (0)