summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2016-09-05 19:12:59 (GMT)
committerBenjamin Peterson <benjamin@python.org>2016-09-05 19:12:59 (GMT)
commit55f445282d92c76d3246b19663641d3007350da0 (patch)
treec653e6cfac5f3d0b79bcfc347e829a155f85e1e1
parent2250c4cb81c4f07164a83b91bf0070247ca4c4b0 (diff)
downloadcpython-55f445282d92c76d3246b19663641d3007350da0.zip
cpython-55f445282d92c76d3246b19663641d3007350da0.tar.gz
cpython-55f445282d92c76d3246b19663641d3007350da0.tar.bz2
remove memory indirections in dict_traverse (closes #27956)
-rw-r--r--Objects/dictobject.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 7a3ed42..d993238 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -2519,24 +2519,26 @@ dict_popitem(PyDictObject *mp)
static int
dict_traverse(PyObject *op, visitproc visit, void *arg)
{
- Py_ssize_t i, n;
PyDictObject *mp = (PyDictObject *)op;
- if (mp->ma_keys->dk_lookup == lookdict) {
- for (i = 0; i < DK_SIZE(mp->ma_keys); i++) {
- if (mp->ma_keys->dk_entries[i].me_value != NULL) {
- Py_VISIT(mp->ma_keys->dk_entries[i].me_value);
- Py_VISIT(mp->ma_keys->dk_entries[i].me_key);
+ PyDictKeysObject *keys = mp->ma_keys;
+ PyDictKeyEntry *entries = &keys->dk_entries[0];
+ Py_ssize_t i, n = DK_SIZE(mp->ma_keys);
+ if (keys->dk_lookup == lookdict) {
+ for (i = 0; i < n; i++) {
+ if (entries[i].me_value != NULL) {
+ Py_VISIT(entries[i].me_value);
+ Py_VISIT(entries[i].me_key);
}
}
} else {
if (mp->ma_values != NULL) {
- for (i = 0, n = DK_SIZE(mp->ma_keys); i < n; i++) {
+ for (i = 0; i < n; i++) {
Py_VISIT(mp->ma_values[i]);
}
}
else {
- for (i = 0, n = DK_SIZE(mp->ma_keys); i < n; i++) {
- Py_VISIT(mp->ma_keys->dk_entries[i].me_value);
+ for (i = 0; i < n; i++) {
+ Py_VISIT(entries[i].me_value);
}
}
}