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