comparison tango/lib/compiler/llvmdc/typeinfo/ti_Ashort.d @ 132:1700239cab2e trunk

[svn r136] MAJOR UNSTABLE UPDATE!!! Initial commit after moving to Tango instead of Phobos. Lots of bugfixes... This build is not suitable for most things.
author lindquist
date Fri, 11 Jan 2008 17:57:40 +0100
parents
children 7816aafeea3c
comparison
equal deleted inserted replaced
131:5825d48b27d1 132:1700239cab2e
1
2 module typeinfo.ti_Ashort;
3
4 private import tango.stdc.string;
5
6 // short[]
7
8 class TypeInfo_As : TypeInfo
9 {
10 char[] toString() { return "short[]"; }
11
12 hash_t getHash(void *p)
13 { short[] s = *cast(short[]*)p;
14 size_t len = s.length;
15 short *str = s.ptr;
16 hash_t hash = 0;
17
18 while (1)
19 {
20 switch (len)
21 {
22 case 0:
23 return hash;
24
25 case 1:
26 hash *= 9;
27 hash += *cast(ushort *)str;
28 return hash;
29
30 default:
31 hash *= 9;
32 hash += *cast(uint *)str;
33 str += 2;
34 len -= 2;
35 break;
36 }
37 }
38
39 return hash;
40 }
41
42 int equals(void *p1, void *p2)
43 {
44 short[] s1 = *cast(short[]*)p1;
45 short[] s2 = *cast(short[]*)p2;
46
47 return s1.length == s2.length &&
48 memcmp(cast(void *)s1, cast(void *)s2, s1.length * short.sizeof) == 0;
49 }
50
51 int compare(void *p1, void *p2)
52 {
53 short[] s1 = *cast(short[]*)p1;
54 short[] s2 = *cast(short[]*)p2;
55 size_t len = s1.length;
56
57 if (s2.length < len)
58 len = s2.length;
59 for (size_t u = 0; u < len; u++)
60 {
61 int result = s1[u] - s2[u];
62 if (result)
63 return result;
64 }
65 if (s1.length < s2.length)
66 return -1;
67 else if (s1.length > s2.length)
68 return 1;
69 return 0;
70 }
71
72 size_t tsize()
73 {
74 return (short[]).sizeof;
75 }
76
77 uint flags()
78 {
79 return 1;
80 }
81
82 TypeInfo next()
83 {
84 return typeid(short);
85 }
86 }
87
88
89 // ushort[]
90
91 class TypeInfo_At : TypeInfo_As
92 {
93 char[] toString() { return "ushort[]"; }
94
95 int compare(void *p1, void *p2)
96 {
97 ushort[] s1 = *cast(ushort[]*)p1;
98 ushort[] s2 = *cast(ushort[]*)p2;
99 size_t len = s1.length;
100
101 if (s2.length < len)
102 len = s2.length;
103 for (size_t u = 0; u < len; u++)
104 {
105 int result = s1[u] - s2[u];
106 if (result)
107 return result;
108 }
109 if (s1.length < s2.length)
110 return -1;
111 else if (s1.length > s2.length)
112 return 1;
113 return 0;
114 }
115
116 TypeInfo next()
117 {
118 return typeid(ushort);
119 }
120 }
121
122 // wchar[]
123
124 class TypeInfo_Au : TypeInfo_At
125 {
126 char[] toString() { return "wchar[]"; }
127
128 TypeInfo next()
129 {
130 return typeid(wchar);
131 }
132 }