Efficient C for ARM
Hoisting
Examples
Doing the same test repeatedly in a loop:
txt->flags |= METRICS; /* for example */ for (i = 0; i < N; i++) { if (txt->flags & TRANSLATE) translate(i); else if (txt->flags & METRICS) get_metrics(i); else draw(i); }
We hoist out the loop:
if (txt->flags & TRANSLATE) { for (i = 0; i < N; i++) translate(i); } else if (txt->flags & METRICS) { for (i = 0; i < N; i++) get_metrics(i); } else { for (i = 0; i < N; i++) draw(i); }


http://www.compileroptimizations.com/category/hoisting.htm (external link)