The chain makes more sense, but it can also be used in the unlikely micro-optimization. During a call, you can avoid storing a temporary value on the stack. For instance:.
char *fn(char *s) { strrev(s); strlwr(s); return strstr(s, "secret"); }
For calls to strrev() and strlwr() you need to keep a safe copy of s for later use. You can delete this register using:
char *fn(char *s) { s = strrev(s); s = strlwr(s); return strstr(s, "secret"); }
According to the response to the chain, you can also use:
char *fn(char *s) { return strstr(strlwr(strrev(s)), "secret"); }
But this can be a problem in more complex code.
I just tried and he excluded three mov instructions. Yay !!
source share