Closed uecasm closed 3 years ago
This code was written historically. I'll check, is ~ operator gives any performance (it seems, no reasonable difference, but I need to check it, sometimes .NET JIT Optimizer gives original results).
I've tested this variants in different ways and environments and did not find any reasonable difference. It seems, JIT peforms all required operations by itself. I have not decide, what code is better to read yet, but there is no sense to change it for preformance reasons.
https://github.com/force-net/Crc32.NET/blob/699351a2a3ac9ac1cdadb1e16d4285e35f44fedd/Crc32.NET/SafeProxy.cs#L40 https://github.com/force-net/Crc32.NET/blob/699351a2a3ac9ac1cdadb1e16d4285e35f44fedd/Crc32.NET/SafeProxy.cs#L73
These are mathematically equivalent to just taking the complement (
~crc
,~crcLocal
, respectively), so why would you write it this way? Taking the complement should always be faster than doing an XOR, although perhaps the compiler is smart enough to do it for you.