summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorHristo Venev <hristo@venev.name>2021-04-29 02:06:03 (GMT)
committerGitHub <noreply@github.com>2021-04-29 02:06:03 (GMT)
commit8557edbfa8f74514de82feea4c62f5963e4e0aa7 (patch)
treee18ba59b1b6e34ad6b9d7c3bb9c6662d51e599db /Objects
parent69a733bda34d413d3ad545ef3132240e5d2a7c0c (diff)
downloadcpython-8557edbfa8f74514de82feea4c62f5963e4e0aa7.zip
cpython-8557edbfa8f74514de82feea4c62f5963e4e0aa7.tar.gz
cpython-8557edbfa8f74514de82feea4c62f5963e4e0aa7.tar.bz2
bpo-24275: Don't downgrade unicode-only dicts to mixed on lookups (GH-25186)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/dictobject.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 44796a6..0aeee70 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -857,7 +857,6 @@ lookdict_unicode(PyDictObject *mp, PyObject *key,
unicodes is to override __eq__, and for speed we don't cater to
that here. */
if (!PyUnicode_CheckExact(key)) {
- mp->ma_keys->dk_lookup = lookdict;
return lookdict(mp, key, hash, value_addr);
}
@@ -900,7 +899,6 @@ lookdict_unicode_nodummy(PyDictObject *mp, PyObject *key,
unicodes is to override __eq__, and for speed we don't cater to
that here. */
if (!PyUnicode_CheckExact(key)) {
- mp->ma_keys->dk_lookup = lookdict;
return lookdict(mp, key, hash, value_addr);
}
@@ -1084,7 +1082,6 @@ insertdict(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject *value)
if (ix == DKIX_ERROR)
goto Fail;
- assert(PyUnicode_CheckExact(key) || mp->ma_keys->dk_lookup == lookdict);
MAINTAIN_TRACKING(mp, key, value);
/* When insertion order is different from shared key, we can't share
@@ -1106,6 +1103,9 @@ insertdict(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject *value)
if (insertion_resize(mp) < 0)
goto Fail;
}
+ if (!PyUnicode_CheckExact(key) && mp->ma_keys->dk_lookup != lookdict) {
+ mp->ma_keys->dk_lookup = lookdict;
+ }
Py_ssize_t hashpos = find_empty_slot(mp->ma_keys, hash);
ep = &DK_ENTRIES(mp->ma_keys)[mp->ma_keys->dk_nentries];
dictkeys_set_index(mp->ma_keys, hashpos, mp->ma_keys->dk_nentries);
@@ -3068,6 +3068,9 @@ PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *defaultobj)
return NULL;
}
}
+ if (!PyUnicode_CheckExact(key) && mp->ma_keys->dk_lookup != lookdict) {
+ mp->ma_keys->dk_lookup = lookdict;
+ }
Py_ssize_t hashpos = find_empty_slot(mp->ma_keys, hash);
ep0 = DK_ENTRIES(mp->ma_keys);
ep = &ep0[mp->ma_keys->dk_nentries];