3 ms·
The code relies on information not present in the program - "this linked list consist mostly of nodes sequentially arranged". If you could express that in your
by groby_b 5y ago
The code relies on information not present in the program - "this linked list consist mostly of nodes sequentially arranged".
If you could express that in your programming language, then yes, the compiler could optimize it. One could argue that the "weird" if statement is just that hint.
And is it useful? It depends. There are plenty of situations where doubling your throughput is worth a lot of effort. There've been situations in my career where I've spent a month or two to shave a cycle or two. It's rare. But when you need it, you want the biggest bag of tricks you can bring, because it really matters :)