3 ms·
It's not limited to bytes. It works with any bitwise comparable primitive i.e. int, long, char, etc. The logic which decides which path to use is here https://
by neonsunset 2y ago
It's not limited to bytes. It works with any bitwise comparable primitive i.e. int, long, char, etc.
The logic which decides which path to use is here https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs#L3416-L3433 https://github.com/dotnet/runtime/blob/main/src/libraries/Sy... and here https://github.com/dotnet/runtime/blob/main/src/coreclr/tools/Common/TypeSystem/IL/Stubs/RuntimeHelpersIntrinsics.cs#L33-L90 https://github.com/dotnet/runtime/blob/main/src/coreclr/tool... (this one is used by ILC for NativeAOT but the C++ impl. for the JIT is going to be similar)
The [Intrinsic] annotation is present because such comparisons on strings/arrays/spans are specially recognized in the compiler to be unrolled and inlined whenever one of the arguments has constant length or is a constant string or a span which points to constant data.