4 ms·
``` if (node != next) { node = node->next; } ``` How does this work? Shouldn't this be ``` if (node != next) { node = next; } ```?
by solidangle 5y ago
```
if (node != next) {
node = node->next;
}
```
How does this work? Shouldn't this be
```
if (node != next) { node = next; }
```?
- deleted 5y ago[deleted]
- xfer 5y agowhile (node) { value += node->value; next = node->next; So it is the same thing.
- tinus_hn 5y agoThat looks weird, why would you need to test if two values are equal if you’re going to assign them to be equal anyway?
- xfer 5y agoThat is the trick. In the happy path you are not assigning(`node=next`). It is taken care of by `node++`, which removes the loop dependency and the processor can use the full instruction level parallelism.
- ectopod 5y agoIt looks like a bug. The unhappy path contains both `node++` and `node=node->next`. Note that this is in the code following "Let’s go back to the code we showed for value speculation in C:", which is actually different from the preceding code it's supposed to be a copy of. I guess it's a typo.
- ectopod 5y agoThe author has fixed this discrepancy now.
- tinus_hn 5y agoIt looks as if the difference is in delaying the check for next == NULL.