comparison druntime/src/compiler/dmd/typeinfo/ti_AC.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_AC;
14
15 // Object[]
16
17 class TypeInfo_AC : TypeInfo
18 {
19 override hash_t getHash(in void* p)
20 { Object[] s = *cast(Object[]*)p;
21 hash_t hash = 0;
22
23 foreach (Object o; s)
24 {
25 if (o)
26 hash += o.toHash();
27 }
28 return hash;
29 }
30
31 override equals_t equals(in void* p1, in void* p2)
32 {
33 Object[] s1 = *cast(Object[]*)p1;
34 Object[] s2 = *cast(Object[]*)p2;
35
36 if (s1.length == s2.length)
37 {
38 for (size_t u = 0; u < s1.length; u++)
39 { Object o1 = s1[u];
40 Object o2 = s2[u];
41
42 // Do not pass null's to Object.opEquals()
43 if (o1 is o2 ||
44 (!(o1 is null) && !(o2 is null) && o1.opEquals(o2)))
45 continue;
46 return false;
47 }
48 return true;
49 }
50 return false;
51 }
52
53 override int compare(in void* p1, in void* p2)
54 {
55 Object[] s1 = *cast(Object[]*)p1;
56 Object[] s2 = *cast(Object[]*)p2;
57 ptrdiff_t c;
58
59 c = cast(ptrdiff_t)s1.length - cast(ptrdiff_t)s2.length;
60 if (c == 0)
61 {
62 for (size_t u = 0; u < s1.length; u++)
63 { Object o1 = s1[u];
64 Object o2 = s2[u];
65
66 if (o1 is o2)
67 continue;
68
69 // Regard null references as always being "less than"
70 if (o1)
71 {
72 if (!o2)
73 { c = 1;
74 break;
75 }
76 c = o1.opCmp(o2);
77 if (c)
78 break;
79 }
80 else
81 { c = -1;
82 break;
83 }
84 }
85 }
86 if (c < 0)
87 c = -1;
88 else if (c > 0)
89 c = 1;
90 return c;
91 }
92
93 override size_t tsize()
94 {
95 return (Object[]).sizeof;
96 }
97
98 override uint flags()
99 {
100 return 1;
101 }
102
103 override TypeInfo next()
104 {
105 return typeid(Object);
106 }
107 }