There was an error while loading. Please reload this page.
1 parent 09bdf83 commit f649b5aCopy full SHA for f649b5a
1 file changed
Objects/dictobject.c
@@ -2520,14 +2520,13 @@ dict_merge(PyObject *a, PyObject *b, int override)
2520
* skips the unnecessary test.
2521
*/
2522
override = 1;
2523
+ PyDictKeysObject *okeys = other->ma_keys;
2524
- // If other is clean combined dict, just clone it.
2525
+ // If other is clean, combined, and just allocated, just clone it.
2526
if (other->ma_values == NULL &&
- other->ma_used == other->ma_keys->dk_nentries &&
2527
- other->ma_keys->dk_size <= other->ma_used * 3 + PyDict_MINSIZE) {
2528
- /* Note: ma_used * 3 must not overflow, because sizeof(dict) is
2529
- * much larger than ma_used * 3.
2530
- */
+ other->ma_used == okeys->dk_nentries &&
+ (okeys->dk_size == PyDict_MINSIZE ||
+ USABLE_FRACTION(okeys->dk_size/2) < other->ma_used)) {
2531
PyDictKeysObject *keys = clone_combined_dict_keys(other);
2532
if (keys == NULL) {
2533
return -1;
0 commit comments