Why C++ compiles slowly
bearophile
bearophileHUGS at lycos.com
Thu Aug 26 13:19:36 PDT 2010
Walter Bright:
> Just for fun, searchfixlist goes back at least to 1983 or so.
It contains this if (I am not able to indent it well):
if (s->Sseg == p->Lseg &&
(s->Sclass == SCstatic ||
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS
(!(config.flags3 & CFG3pic) && s->Sclass == SCglobal)) &&
#else
s->Sclass == SCglobal) &&
#endif
s->Sxtrnnum == 0 && p->Lflags & CFselfrel) {
How do you rewrite that in good D code? A possible way is to split that messy if into two nested ifs. Between first and second if you define a boolean variable in two different ways using a static if. And in the second if you use the boolean variable and the second part of the runtime test. Something like this:
if (part1) {
static if (versions_test) {
bool aux = ...
} else {
bool aux = ...
}
if (aux && part2) {
// ...
} else {
// ...
}
}
aux is defined in the middle and not before the first if because performing this runtime test is not necessary when part1 fails.
Bye,
bearophile
More information about the Digitalmars-d
mailing list