[Python-Dev] cpython: Minor bit of factoring-out common code.
Serhiy Storchaka
storchaka at gmail.com
Tue Jul 7 09:19:37 CEST 2015
On 07.07.15 05:08, raymond.hettinger wrote:
> https://hg.python.org/cpython/rev/5088f2cd6293
> changeset: 96866:5088f2cd6293
> user: Raymond Hettinger <python at rcn.com>
> date: Mon Jul 06 19:08:49 2015 -0700
> summary:
> Minor bit of factoring-out common code.
> + if (rv < 0)
> + goto error;
> if (rv) {
> - if (set_add_entry(result, key, hash)) {
> - Py_DECREF(it);
> - Py_DECREF(result);
> - Py_DECREF(key);
> - return NULL;
> - }
> + if (set_add_entry(result, key, hash))
> + goto error;
> }
> Py_DECREF(key);
> }
In tight loop it may be worth to rewrite the code
if (rv < 0)
goto error;
if (rv) {
expensive_operation();
}
// if (rv == 0) do nothing
in the form:
if (rv) {
if (rv < 0)
goto error;
expensive_operation();
}
This looks less clear, but needs only one test in the case of rv == 0.
More information about the Python-Dev
mailing list