1 2 module rt.compiler.ldc.typeinfo.ti_Ashort; 3 4 private import tango.stdc.string : memcmp; 5 private import rt.compiler.util.hash; 6 7 // short[] 8 9 class TypeInfo_As : TypeInfo_Array 10 { 11 override char[] toString() { return "short[]"; } 12 13 override hash_t getHash(in void* p) 14 { short[] s = *cast(short[]*)p; 15 size_t len = s.length; 16 short *str = s.ptr; 17 return rt_hash_str(str,len*short.sizeof,0); 18 } 19 20 override equals_t equals(in void* p1, in void* p2) 21 { 22 short[] s1 = *cast(short[]*)p1; 23 short[] s2 = *cast(short[]*)p2; 24 25 return s1.length == s2.length && 26 memcmp(cast(void *)s1, cast(void *)s2, s1.length * short.sizeof) == 0; 27 } 28 29 override int compare(in void* p1, in void* p2) 30 { 31 short[] s1 = *cast(short[]*)p1; 32 short[] s2 = *cast(short[]*)p2; 33 size_t len = s1.length; 34 35 if (s2.length < len) 36 len = s2.length; 37 for (size_t u = 0; u < len; u++) 38 { 39 int result = s1[u] - s2[u]; 40 if (result) 41 return result; 42 } 43 if (s1.length < s2.length) 44 return -1; 45 else if (s1.length > s2.length) 46 return 1; 47 return 0; 48 } 49 50 override size_t talign() 51 { 52 return (short[]).alignof; 53 } 54 55 override size_t tsize() 56 { 57 return (short[]).sizeof; 58 } 59 60 override uint flags() 61 { 62 return 1; 63 } 64 65 override TypeInfo next() 66 { 67 return typeid(short); 68 } 69 } 70 71 72 // ushort[] 73 74 class TypeInfo_At : TypeInfo_As 75 { 76 override char[] toString() { return "ushort[]"; } 77 78 override int compare(in void* p1, in void* p2) 79 { 80 ushort[] s1 = *cast(ushort[]*)p1; 81 ushort[] s2 = *cast(ushort[]*)p2; 82 size_t len = s1.length; 83 84 if (s2.length < len) 85 len = s2.length; 86 for (size_t u = 0; u < len; u++) 87 { 88 int result = s1[u] - s2[u]; 89 if (result) 90 return result; 91 } 92 if (s1.length < s2.length) 93 return -1; 94 else if (s1.length > s2.length) 95 return 1; 96 return 0; 97 } 98 99 override TypeInfo next() 100 { 101 return typeid(ushort); 102 } 103 } 104 105 // wchar[] 106 107 class TypeInfo_Au : TypeInfo_At 108 { 109 override char[] toString() { return "wchar[]"; } 110 111 // getHash should be overridden and call rt_hash_utf16 if one wants dependence for codepoints only 112 override TypeInfo next() 113 { 114 return typeid(wchar); 115 } 116 }