| ▲ | zephen a day ago | |
The article author claims that his new version is simpler than the old version. But the new version is really only simpler TEXTUALLY, because of the post-increment operators: push(val) { assert(!full()); array[mask(write++)] = val; } shift() { assert(!empty()); return array[mask(read++)]; } (If you look at assembly output, it's probably the same or more code.) But, at least in some languages, those increments might happen before the array access, which could mean that using them causes a race condition. In fact, in C or C++, those increments are GUARANTEED to happen before the access to array, because they are guaranteed to happen before the calls to mask. tl;dr -- dude claims to insure he can utilize one more character of his buffer, while writing code that ensures that if he is truly operating at the margins, he will be doing things in the wrong order. | ||