comparison druntime/src/compiler/dmd/typeinfo/ti_Ashort.d @ 1458:e0b2d67cfe7c

Added druntime (this should be removed once it works).
author Robert Clipsham <robert@octarineparrot.com>
date Tue, 02 Jun 2009 17:43:06 +0100
parents
children
comparison
equal deleted inserted replaced
1456:7b218ec1044f 1458:e0b2d67cfe7c
1 /**
2 * TypeInfo support code.
3 *
4 * Copyright: Copyright Digital Mars 2004 - 2009.
5 * License: <a href="http://www.boost.org/LICENSE_1_0.txt>Boost License 1.0</a>.
6 * Authors: Walter Bright
7 *
8 * Copyright Digital Mars 2004 - 2009.
9 * Distributed under the Boost Software License, Version 1.0.
10 * (See accompanying file LICENSE_1_0.txt or copy at
11 * http://www.boost.org/LICENSE_1_0.txt)
12 */
13 module rt.typeinfo.ti_Ashort;
14
15 private import core.stdc.string;
16
17 // short[]
18
19 class TypeInfo_As : TypeInfo
20 {
21 override string toString() { return "short[]"; }
22
23 override hash_t getHash(in void* p)
24 { short[] s = *cast(short[]*)p;
25 size_t len = s.length;
26 short *str = s.ptr;
27 hash_t hash = 0;
28
29 while (1)
30 {
31 switch (len)
32 {
33 case 0:
34 return hash;
35
36 case 1:
37 hash *= 9;
38 hash += *cast(ushort *)str;
39 return hash;
40
41 default:
42 hash *= 9;
43 hash += *cast(uint *)str;
44 str += 2;
45 len -= 2;
46 break;
47 }
48 }
49
50 return hash;
51 }
52
53 override equals_t equals(in void* p1, in void* p2)
54 {
55 short[] s1 = *cast(short[]*)p1;
56 short[] s2 = *cast(short[]*)p2;
57
58 return s1.length == s2.length &&
59 memcmp(cast(void *)s1, cast(void *)s2, s1.length * short.sizeof) == 0;
60 }
61
62 override int compare(in void* p1, in void* p2)
63 {
64 short[] s1 = *cast(short[]*)p1;
65 short[] s2 = *cast(short[]*)p2;
66 size_t len = s1.length;
67
68 if (s2.length < len)
69 len = s2.length;
70 for (size_t u = 0; u < len; u++)
71 {
72 int result = s1[u] - s2[u];
73 if (result)
74 return result;
75 }
76 if (s1.length < s2.length)
77 return -1;
78 else if (s1.length > s2.length)
79 return 1;
80 return 0;
81 }
82
83 override size_t tsize()
84 {
85 return (short[]).sizeof;
86 }
87
88 override uint flags()
89 {
90 return 1;
91 }
92
93 override TypeInfo next()
94 {
95 return typeid(short);
96 }
97 }
98
99
100 // ushort[]
101
102 class TypeInfo_At : TypeInfo_As
103 {
104 override string toString() { return "ushort[]"; }
105
106 override int compare(in void* p1, in void* p2)
107 {
108 ushort[] s1 = *cast(ushort[]*)p1;
109 ushort[] s2 = *cast(ushort[]*)p2;
110 size_t len = s1.length;
111
112 if (s2.length < len)
113 len = s2.length;
114 for (size_t u = 0; u < len; u++)
115 {
116 int result = s1[u] - s2[u];
117 if (result)
118 return result;
119 }
120 if (s1.length < s2.length)
121 return -1;
122 else if (s1.length > s2.length)
123 return 1;
124 return 0;
125 }
126
127 override TypeInfo next()
128 {
129 return typeid(ushort);
130 }
131 }
132
133 // wchar[]
134
135 class TypeInfo_Au : TypeInfo_At
136 {
137 override string toString() { return "wchar[]"; }
138
139 override TypeInfo next()
140 {
141 return typeid(wchar);
142 }
143 }