summaryrefslogtreecommitdiff
path: root/WorldlineKeepers/Assets/ThirdParty/UnsafeFunction.cs
blob: 33626269722d3e5b35c4830c88d7394549b80aed (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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;



public class UnsafeFunction
{

    public unsafe static void memcpyimpl(byte* src, byte* dest, int len)
    {
        if (len >= 16)
        {
            do
            {
                *(int*)dest = *(int*)src;
                *(int*)(dest + 4) = *(int*)(src + 4);
                *(int*)(dest + 8) = *(int*)(src + 8);
                *(int*)(dest + 12) = *(int*)(src + 12);
                dest += 16;
                src += 16;
            }
            while ((len -= 16) >= 16);
        }
        if (len > 0)
        {
            if ((len & 8) != 0)
            {
                *(int*)dest = *(int*)src;
                *(int*)(dest + 4) = *(int*)(src + 4);
                dest += 8;
                src += 8;
            }
            if ((len & 4) != 0)
            {
                *(int*)dest = *(int*)src;
                dest += 4;
                src += 4;
            }
            if ((len & 2) != 0)
            {
                *(short*)dest = *(short*)src;
                dest += 2;
                src += 2;
            }
            if ((len & 1) != 0)
            {
                *(dest++) = *(src++);
            }
        }
    }

}