diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-06-03 04:14:43 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-06-03 04:14:43 (GMT) |
commit | 7b5d0afb1ec0e9cc10e74779d0e80bb1bee83577 (patch) | |
tree | 93cc3e06b1c4e09352bec9a8a5696a1433ae1ec0 /Objects/dictobject.c | |
parent | 00d0cb6ec3198234f27e98fca9ee6e152dd8abeb (diff) | |
download | cpython-7b5d0afb1ec0e9cc10e74779d0e80bb1bee83577.zip cpython-7b5d0afb1ec0e9cc10e74779d0e80bb1bee83577.tar.gz cpython-7b5d0afb1ec0e9cc10e74779d0e80bb1bee83577.tar.bz2 |
lookdict: Reduce obfuscating code duplication with a judicious goto.
This code is likely to get even hairier to squash core dumps due to
mutating comparisons, and it's hard enough to follow without that.
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 0797e4b..69fe67e 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -251,8 +251,8 @@ lookdict(dictobject *mp, PyObject *key, register long hash) register unsigned int mask = mp->ma_size-1; dictentry *ep0 = mp->ma_table; register dictentry *ep; - register int restore_error = 0; - register int checked_error = 0; + register int restore_error; + register int checked_error; register int cmp; PyObject *err_type, *err_value, *err_tb; @@ -260,6 +260,8 @@ lookdict(dictobject *mp, PyObject *key, register long hash) ep = &ep0[i]; if (ep->me_key == NULL || ep->me_key == key) return ep; + + restore_error = checked_error = 0; if (ep->me_key == dummy) freeslot = ep; else { @@ -271,13 +273,9 @@ lookdict(dictobject *mp, PyObject *key, register long hash) PyErr_Fetch(&err_type, &err_value, &err_tb); } cmp = PyObject_RichCompareBool(ep->me_key, key, Py_EQ); - if (cmp > 0) { - if (restore_error) - PyErr_Restore(err_type, err_value, - err_tb); - return ep; - } - else if (cmp < 0) + if (cmp > 0) + goto Done; + if (cmp < 0) PyErr_Clear(); } freeslot = NULL; @@ -289,16 +287,13 @@ lookdict(dictobject *mp, PyObject *key, register long hash) i = (i << 2) + i + perturb + 1; ep = &ep0[i & mask]; if (ep->me_key == NULL) { - if (restore_error) - PyErr_Restore(err_type, err_value, err_tb); - return freeslot == NULL ? ep : freeslot; + if (freeslot != NULL) + ep = freeslot; + break; } - if (ep->me_key == key) { - if (restore_error) - PyErr_Restore(err_type, err_value, err_tb); - return ep; - } - else if (ep->me_hash == hash && ep->me_key != dummy) { + if (ep->me_key == key) + break; + if (ep->me_hash == hash && ep->me_key != dummy) { if (!checked_error) { checked_error = 1; if (PyErr_Occurred()) { @@ -308,18 +303,19 @@ lookdict(dictobject *mp, PyObject *key, register long hash) } } cmp = PyObject_RichCompareBool(ep->me_key, key, Py_EQ); - if (cmp > 0) { - if (restore_error) - PyErr_Restore(err_type, err_value, - err_tb); - return ep; - } - else if (cmp < 0) + if (cmp > 0) + break; + if (cmp < 0) PyErr_Clear(); } else if (ep->me_key == dummy && freeslot == NULL) freeslot = ep; } + +Done: + if (restore_error) + PyErr_Restore(err_type, err_value, err_tb); + return ep; } /* |