Debugging recently, another piece of someone else's code I stumbled on this cycle:
while (--i ^ -1) /* loop body */;
in this case, initially, i is equal to some positive number. That is, the bitwise operator is used for integers. A little thought, I realized that the result of a bitwise XOR will be nonzero only in the case when numbers are equal. Then the condition in kastritsa true. Otherwise, it will be non-zero, which kastritsa in false.
It turns out, you can use the bitwise XOR operator instead of != (if we know in advance that the compared values are the numbers).
Here I have a question I want to put in front of an audience.
Why the author uses XOR?
Last night I pondered this and the most plausible cause, I found the desire to write "cool obscure code". Immediately I remembered how I was when I started to learn the basics of programming, suddenly discovered that can write "concise code that is difficult to understand and which works." It seemed to me that this is evidence of some skill. In fact, it is clear that this is evidence to the contrary. In favor of this hypothesis also had what the rest of the code in the area given snippet was written in a similar way.
However, I did not give rest to another thought. I imagined that if I wanted to complicate the code, I'd somehow not thought to use XOR, even if I knew about this possibility.
As a result (trying unsuccessfully to sleep for two hours :) ), I got up, went to my computer and I have written script that did a lot of comparisons to those other ways and measured the time.
It turned out that if you use a bitwise XOR instead of !=, you receive a boost in performance (at least on Firefox), this increase is stable (that is, he is always there, some more, some less), but is only around 1%.
Maybe there are still some features that gives the advantage of the bitwise XOR?