int Foo0(int index) { return Impl.ProductsArray[index]; } int Foo0a(int index) { ref int rawArray = ref MemoryMarshal.GetArrayDataReference(Impl.ProductsArray); return Unsafe.AddByteOffset(ref rawArray, (IntPtr)(index * sizeof(int))); } int Foo1(int index) { return Impl.ProductsPtr[index]; } static class Impl { internal static readonly int[] ProductsArray = new int[] { 0x090000,0x000900,0x040102,0x010402 }; internal static ReadOnlySpan ProductsSpan => new byte[] { 0x00,0x00,0x09,0x00, 0x00,0x09,0x00,0x00, 0x02,0x01,0x04,0x00, 0x02,0x04,0x01,0x00 }; internal static readonly unsafe int* ProductsPtr = (int*)Unsafe.AsPointer(ref Unsafe.AsRef(ProductsSpan.GetPinnableReference())); } ---
g__Foo0|4_0 (Int32) L0000 push rsi L0001 sub rsp, 0x20 L0005 mov esi, ecx L0007 mov rcx, 0x7ffa20a8cde0 L0011 mov edx, 1 L0016 call 0x00007ffa7fb391e0 L001b mov rax, [rax] L001e cmp esi, [rax+8] L0021 jae short L0030 L0023 movsxd rdx, esi L0026 mov eax, [rax+rdx*4+0x10] L002a add rsp, 0x20 L002e pop rsi L002f ret L0030 call 0x00007ffa7fb3abc0 L0035 int3
g__Foo0a|4_1 (Int32) L0000 push rsi L0001 sub rsp, 0x20 L0005 mov esi, ecx L0007 mov rcx, 0x7ffa20a8cde0 L0011 mov edx, 1 L0016 call 0x00007ffa7fb391e0 L001b mov rax, [rax] L001e cmp [rax], eax L0020 add rax, 0x10 L0024 shl esi, 2 L0027 movsxd rdx, esi L002a mov eax, [rax+rdx] L002d add rsp, 0x20 L0031 pop rsi L0032 ret
g__Foo1|4_2 (Int32) L0000 push rsi L0001 sub rsp, 0x20 L0005 mov esi, ecx L0007 mov rcx, 0x7ffa20a8cde0 L0011 mov edx, 1 L0016 call 0x00007ffa7fb393b0 L001b mov rax, [rax+8] L001f movsxd rdx, esi L0022 mov eax, [rax+rdx*4] L0025 add rsp, 0x20 L0029 pop rsi L002a ret