Welcome to mirror list, hosted at ThFree Co, Russian Federation.

UnsafeMemory.Low.cs « Internal « MessagePack « src - github.com/aspnet/MessagePack-CSharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1684038c6f188806283721efb16910135771832a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#if NETSTANDARD || NETFRAMEWORK

using System;
using System.Runtime.CompilerServices;

namespace MessagePack.Internal
{
    // for string key property name write optimization.

    public static class UnsafeMemory
    {
        public static readonly bool Is32Bit = (IntPtr.Size == 4);
    }

    public static partial class UnsafeMemory32
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static unsafe int WriteRaw1(ref byte[] dst, int dstOffset, byte[] src)
        {
            MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);

            fixed (byte* pSrc = &src[0])
            fixed (byte* pDst = &dst[dstOffset])
            {
                *(byte*)pDst = *(byte*)pSrc;
            }

            return src.Length;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static unsafe int WriteRaw2(ref byte[] dst, int dstOffset, byte[] src)
        {
            MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);

            fixed (byte* pSrc = &src[0])
            fixed (byte* pDst = &dst[dstOffset])
            {
                *(short*)pDst = *(short*)pSrc;
            }

            return src.Length;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static unsafe int WriteRaw3(ref byte[] dst, int dstOffset, byte[] src)
        {
            MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);

            fixed (byte* pSrc = &src[0])
            fixed (byte* pDst = &dst[dstOffset])
            {
                *(byte*)pDst = *(byte*)pSrc;
                *(short*)(pDst + 1) = *(short*)(pSrc + 1);
            }

            return src.Length;
        }
    }

    public static partial class UnsafeMemory64
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static unsafe int WriteRaw1(ref byte[] dst, int dstOffset, byte[] src)
        {
            MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);

            fixed (byte* pSrc = &src[0])
            fixed (byte* pDst = &dst[dstOffset])
            {
                *(byte*)pDst = *(byte*)pSrc;
            }

            return src.Length;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static unsafe int WriteRaw2(ref byte[] dst, int dstOffset, byte[] src)
        {
            MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);

            fixed (byte* pSrc = &src[0])
            fixed (byte* pDst = &dst[dstOffset])
            {
                *(short*)pDst = *(short*)pSrc;
            }

            return src.Length;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static unsafe int WriteRaw3(ref byte[] dst, int dstOffset, byte[] src)
        {
            MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);

            fixed (byte* pSrc = &src[0])
            fixed (byte* pDst = &dst[dstOffset])
            {
                *(byte*)pDst = *(byte*)pSrc;
                *(short*)(pDst + 1) = *(short*)(pSrc + 1);
            }

            return src.Length;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static unsafe int WriteRaw4(ref byte[] dst, int dstOffset, byte[] src)
        {
            MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);

            fixed (byte* pSrc = &src[0])
            fixed (byte* pDst = &dst[dstOffset])
            {
                *(int*)(pDst + 0) = *(int*)(pSrc + 0);
            }

            return src.Length;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static unsafe int WriteRaw5(ref byte[] dst, int dstOffset, byte[] src)
        {
            MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);

            fixed (byte* pSrc = &src[0])
            fixed (byte* pDst = &dst[dstOffset])
            {
                *(int*)(pDst + 0) = *(int*)(pSrc + 0);
                *(int*)(pDst + 1) = *(int*)(pSrc + 1);
            }

            return src.Length;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static unsafe int WriteRaw6(ref byte[] dst, int dstOffset, byte[] src)
        {
            MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);

            fixed (byte* pSrc = &src[0])
            fixed (byte* pDst = &dst[dstOffset])
            {
                *(int*)(pDst + 0) = *(int*)(pSrc + 0);
                *(int*)(pDst + 2) = *(int*)(pSrc + 2);
            }

            return src.Length;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static unsafe int WriteRaw7(ref byte[] dst, int dstOffset, byte[] src)
        {
            MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);

            fixed (byte* pSrc = &src[0])
            fixed (byte* pDst = &dst[dstOffset])
            {
                *(int*)(pDst + 0) = *(int*)(pSrc + 0);
                *(int*)(pDst + 3) = *(int*)(pSrc + 3);
            }

            return src.Length;
        }
    }
}

#endif