1 
2 module rt.compiler.dmd.typeinfo.ti_Ashort;
3 
4 private import tango.stdc.string : memcmp;
5 private import rt.compiler.util.hash;
6 
7 // short[]
8 
9 class TypeInfo_As : TypeInfo_Array
10 {
11     override char[] toString() { return "short[]"; }
12 
13     override hash_t getHash(in void* p)
14     {   short[] s = *cast(short[]*)p;
15         size_t len = s.length;
16         short *str = s.ptr;
17         return rt_hash_str(str,len*short.sizeof,0);
18     }
19 
20     override equals_t equals(in void* p1, in void* p2)
21     {
22         short[] s1 = *cast(short[]*)p1;
23         short[] s2 = *cast(short[]*)p2;
24 
25         return s1.length == s2.length &&
26                memcmp(cast(void *)s1, cast(void *)s2, s1.length * short.sizeof) == 0;
27     }
28 
29     override int compare(in void* p1, in void* p2)
30     {
31         short[] s1 = *cast(short[]*)p1;
32         short[] s2 = *cast(short[]*)p2;
33         size_t len = s1.length;
34 
35         if (s2.length < len)
36             len = s2.length;
37         for (size_t u = 0; u < len; u++)
38         {
39             int result = s1[u] - s2[u];
40             if (result)
41                 return result;
42         }
43         if (s1.length < s2.length)
44             return -1;
45         else if (s1.length > s2.length)
46             return 1;
47         return 0;
48     }
49 
50     override size_t talign()
51     {
52         return (short[]).alignof;
53     }
54 
55     override size_t tsize()
56     {
57         return (short[]).sizeof;
58     }
59 
60     override uint flags()
61     {
62         return 1;
63     }
64 
65     override TypeInfo next()
66     {
67         return typeid(short);
68     }
69 
70     version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2)
71     {
72         arg1 = typeid(size_t);
73         arg2 = typeid(void*);
74         return 0;
75     }
76 }
77 
78 
79 // ushort[]
80 
81 class TypeInfo_At : TypeInfo_As
82 {
83     override char[] toString() { return "ushort[]"; }
84 
85     override int compare(in void* p1, in void* p2)
86     {
87         ushort[] s1 = *cast(ushort[]*)p1;
88         ushort[] s2 = *cast(ushort[]*)p2;
89         size_t len = s1.length;
90 
91         if (s2.length < len)
92             len = s2.length;
93         for (size_t u = 0; u < len; u++)
94         {
95             int result = s1[u] - s2[u];
96             if (result)
97                 return result;
98         }
99         if (s1.length < s2.length)
100             return -1;
101         else if (s1.length > s2.length)
102             return 1;
103         return 0;
104     }
105 
106     override TypeInfo next()
107     {
108         return typeid(ushort);
109     }
110 }
111 
112 // wchar[]
113 
114 class TypeInfo_Au : TypeInfo_At
115 {
116     override char[] toString() { return "wchar[]"; }
117 
118     // getHash should be overridden and call rt_hash_utf16 if one wants dependence for codepoints only
119     override TypeInfo next()
120     {
121         return typeid(wchar);
122     }
123 }