diff --git a/MsgPack/Detail/StringComparisonHelper.cs b/MsgPack/Detail/StringComparisonHelper.cs index 024c7fa..c7cdb95 100644 --- a/MsgPack/Detail/StringComparisonHelper.cs +++ b/MsgPack/Detail/StringComparisonHelper.cs @@ -3,22 +3,25 @@ namespace CitizenFX.MsgPack.Detail { - [StructLayout(LayoutKind.Explicit)] - internal unsafe struct StringComparisonHelper - { - [FieldOffset(0)] public fixed byte u8[8]; - [FieldOffset(0)] public fixed ushort u16[4]; - [FieldOffset(0)] public fixed uint u32[2]; - [FieldOffset(0)] public fixed ulong u64[1]; + [StructLayout(LayoutKind.Explicit)] + internal unsafe struct StringComparisonHelper + { + [FieldOffset(0)] public fixed byte u8[8]; + [FieldOffset(0)] public fixed ushort u16[4]; + [FieldOffset(0)] public fixed uint u32[2]; + [FieldOffset(0)] public fixed ulong u64[1]; - public StringComparisonHelper(string str, int offset = 0) - { - int length = str.Length - offset; - if (length > 8) - length = 8; + public StringComparisonHelper(string str, int offset = 0) + { + fixed (byte* pU8 = u8) + { + int length = str.Length - offset; + if (length > 8) + length = 8; - for (int i = 0; i < length; ++i) - u8[i] = (byte)str[i - offset]; - } - } -} + for (int i = 0; i < length; ++i) + pU8[i] = (byte)str[i + offset]; + } + } + } +} \ No newline at end of file