|
Archive:
Subtopics:
Comments disabled |
Sat, 27 Oct 2018
A fun optimization trick from rsync
I was looking at the
The key item here is the static The actual code is a little more sophisticated than this. The list of
cases is built depending on the setting of several compile-time config
flags, so that the code that is compiled only includes the methods
that are actually callable. Calling one of the methods can produce
three distinguishable results: success, real failure (because of
permission problems or some such), or a sort of fake failure
(
case 7:
if (method_7_works(...))
break;
if (errno != ENOSYS)
return -1; /* real failure */
switch_step++;
/* FALLTHROUGH */
On top of this there's another trick: since the various cases are
conditionally compiled depending on the config flags, we don't know
ahead of time which ones will be included. So the
#include "case_N.h"
if (method_7_works(...))
break;
...
#include "case_N.h"
if (method_8_works(...))
break;
...
The first time we
Unfortunately you can only use this trick one switch per file.
Although I suppose if you really wanted to reuse it you could make a
[ Addendum 20181028: Simon Tatham brought up a technique for
generating the [Other articles in category /prog] permanent link |