Message246395
For now multiple set functions call helpers that returns one of three possible values (0, 1, and -1 for error) and then analyze return code in the loop.
while (...) {
rv = some_set_operation();
if (rv < 0) {
// clean up
return NULL;
}
if (rv) {
other_set_operation();
}
// if (rv == 0) do nothing
}
If rv is 0 or 1, it is tested two times. If rv is -1 (unlikely), it is tested only once.
It is possible to rewrite testing in other way:
while (...) {
rv = some_set_operation();
if (rv != 0) { // 1 or -1
if (rv < 0) {
// clean up
return NULL;
}
other_set_operation();
}
}
Now if rv is 0 (common case), it is tested only once, and likely the test jump will be merged with unconditional loop jump.
I have no benchmarking results, but I suppose that such rewritting will generate better machine code. |
|
Date |
User |
Action |
Args |
2015-07-07 08:38:26 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger |
2015-07-07 08:38:26 | serhiy.storchaka | set | messageid: <1436258306.82.0.639469494764.issue24582@psf.upfronthosting.co.za> |
2015-07-07 08:38:26 | serhiy.storchaka | link | issue24582 messages |
2015-07-07 08:38:26 | serhiy.storchaka | create | |
|