1 
2 module rt.compiler.ldc.typeinfo.ti_Ag;
3 
4 private import rt.compiler.util.string;
5 private import rt.compiler.util.hash;
6 private import tango.stdc.string : memcmp;
7 
8 // byte[]
9 
10 class TypeInfo_Ag : TypeInfo_Array
11 {
12     override char[] toString() { return "byte[]"; }
13 
14     override hash_t getHash(in void* p) {
15         byte[] s = *cast(byte[]*)p;
16         size_t len = s.length;
17         byte *str = s.ptr;
18         return rt_hash_str(str,len*byte.sizeof,0);
19     }
20 
21     override equals_t equals(in void* p1, in void* p2)
22     {
23         byte[] s1 = *cast(byte[]*)p1;
24         byte[] s2 = *cast(byte[]*)p2;
25 
26         return s1.length == s2.length &&
27                memcmp(cast(byte *)s1, cast(byte *)s2, s1.length) == 0;
28     }
29 
30     override int compare(in void* p1, in void* p2)
31     {
32         byte[] s1 = *cast(byte[]*)p1;
33         byte[] s2 = *cast(byte[]*)p2;
34         size_t len = s1.length;
35 
36         if (s2.length < len)
37             len = s2.length;
38         for (size_t u = 0; u < len; u++)
39         {
40             int result = s1[u] - s2[u];
41             if (result)
42                 return result;
43         }
44         if (s1.length < s2.length)
45             return -1;
46         else if (s1.length > s2.length)
47             return 1;
48         return 0;
49     }
50 
51     override size_t talign()
52     {
53         return (byte[]).alignof;
54     }
55 
56     override size_t tsize()
57     {
58         return (byte[]).sizeof;
59     }
60 
61     override uint flags()
62     {
63         return 1;
64     }
65 
66     override TypeInfo next()
67     {
68         return typeid(byte);
69     }
70 }
71 
72 
73 // ubyte[]
74 
75 class TypeInfo_Ah : TypeInfo_Ag
76 {
77     override char[] toString() { return "ubyte[]"; }
78 
79     override int compare(in void* p1, in void* p2)
80     {
81         char[] s1 = *cast(char[]*)p1;
82         char[] s2 = *cast(char[]*)p2;
83 
84         return stringCompare(s1, s2);
85     }
86 
87     override TypeInfo next()
88     {
89         return typeid(ubyte);
90     }
91 }
92 
93 // void[]
94 
95 class TypeInfo_Av : TypeInfo_Ah
96 {
97     override char[] toString() { return "void[]"; }
98 
99     override TypeInfo next()
100     {
101         return typeid(void);
102     }
103 }
104 
105 // bool[]
106 
107 class TypeInfo_Ab : TypeInfo_Ah
108 {
109     override char[] toString() { return "bool[]"; }
110 
111     override TypeInfo next()
112     {
113         return typeid(bool);
114     }
115 }
116 
117 // char[]
118 
119 class TypeInfo_Aa : TypeInfo_Ag
120 {
121     override char[] toString() { return "char[]"; }
122 
123     override hash_t getHash(in void* p){
124         char[] s = *cast(char[]*)p;
125         version (OldHash)
126         {
127             hash_t hash = 0;
128             foreach (char c; s)
129                 hash = hash * 11 + c;
130             return hash;
131         } else {
132             //return rt_hash_utf8(s,0); // this would be encoding independent
133             return rt_hash_str(s.ptr,s.length,0);
134         }
135     }
136 
137     override TypeInfo next()
138     {
139         return typeid(char);
140     }
141 }