14
14
using System . Runtime ;
15
15
using System . Runtime . CompilerServices ;
16
16
17
- using Internal . Runtime . Augments ;
17
+ using Internal . Runtime ;
18
18
19
19
using Debug = System . Diagnostics . Debug ;
20
20
@@ -39,15 +39,15 @@ public abstract class ValueType
39
39
// This API is a bit awkward because we want to avoid burning more than one vtable slot on this.
40
40
// When index == GetNumFields, this method is expected to return the number of fields of this
41
41
// valuetype. Otherwise, it returns the offset and type handle of the index-th field on this type.
42
- internal virtual int __GetFieldHelper ( int index , out EETypePtr eeType )
42
+ internal virtual unsafe int __GetFieldHelper ( int index , out MethodTable * mt )
43
43
{
44
44
// Value types that don't override this method will use the fast path that looks at bytes, not fields.
45
45
Debug . Assert ( index == GetNumFields ) ;
46
- eeType = default ;
46
+ mt = default ;
47
47
return UseFastHelper ;
48
48
}
49
49
50
- public override bool Equals ( [ NotNullWhen ( true ) ] object ? obj )
50
+ public override unsafe bool Equals ( [ NotNullWhen ( true ) ] object ? obj )
51
51
{
52
52
if ( obj == null || obj . GetEETypePtr ( ) != this . GetEETypePtr ( ) )
53
53
return false ;
@@ -71,7 +71,7 @@ public override bool Equals([NotNullWhen(true)] object? obj)
71
71
// Foreach field, box and call the Equals method.
72
72
for ( int i = 0 ; i < numFields ; i ++ )
73
73
{
74
- int fieldOffset = __GetFieldHelper ( i , out EETypePtr fieldType ) ;
74
+ int fieldOffset = __GetFieldHelper ( i , out MethodTable * fieldType ) ;
75
75
76
76
// Fetch the value of the field on both types
77
77
object thisField = RuntimeImports . RhBoxAny ( ref Unsafe . Add ( ref thisRawData , fieldOffset ) , fieldType ) ;
@@ -102,22 +102,22 @@ public override int GetHashCode()
102
102
return hashCode ;
103
103
}
104
104
105
- private int GetHashCodeImpl ( )
105
+ private unsafe int GetHashCodeImpl ( )
106
106
{
107
107
int numFields = __GetFieldHelper ( GetNumFields , out _ ) ;
108
108
109
109
if ( numFields == UseFastHelper )
110
- return FastGetValueTypeHashCodeHelper ( this . GetEETypePtr ( ) , ref this . GetRawData ( ) ) ;
110
+ return FastGetValueTypeHashCodeHelper ( this . GetMethodTable ( ) , ref this . GetRawData ( ) ) ;
111
111
112
112
return RegularGetValueTypeHashCode ( ref this . GetRawData ( ) , numFields ) ;
113
113
}
114
114
115
- private static int FastGetValueTypeHashCodeHelper ( EETypePtr type , ref byte data )
115
+ private static unsafe int FastGetValueTypeHashCodeHelper ( MethodTable * type , ref byte data )
116
116
{
117
117
// Sanity check - if there are GC references, we should not be hashing bytes
118
- Debug . Assert ( ! type . HasPointers ) ;
118
+ Debug . Assert ( ! type -> HasGCPointers ) ;
119
119
120
- int size = ( int ) type . ValueTypeSize ;
120
+ int size = ( int ) type -> ValueTypeSize ;
121
121
int hashCode = 0 ;
122
122
123
123
for ( int i = 0 ; i < size / 4 ; i ++ )
@@ -128,31 +128,31 @@ private static int FastGetValueTypeHashCodeHelper(EETypePtr type, ref byte data)
128
128
return hashCode ;
129
129
}
130
130
131
- private int RegularGetValueTypeHashCode ( ref byte data , int numFields )
131
+ private unsafe int RegularGetValueTypeHashCode ( ref byte data , int numFields )
132
132
{
133
133
int hashCode = 0 ;
134
134
135
135
// We only take the hashcode for the first non-null field. That's what the CLR does.
136
136
for ( int i = 0 ; i < numFields ; i ++ )
137
137
{
138
- int fieldOffset = __GetFieldHelper ( i , out EETypePtr fieldType ) ;
138
+ int fieldOffset = __GetFieldHelper ( i , out MethodTable * fieldType ) ;
139
139
ref byte fieldData = ref Unsafe . Add ( ref data , fieldOffset ) ;
140
140
141
- Debug . Assert ( ! fieldType . IsPointer ) ;
141
+ Debug . Assert ( ! fieldType -> IsPointerType ) ;
142
142
143
- if ( fieldType . ElementType == Internal . Runtime . EETypeElementType . Single )
143
+ if ( fieldType -> ElementType == EETypeElementType . Single )
144
144
{
145
145
hashCode = Unsafe . As < byte , float > ( ref fieldData ) . GetHashCode ( ) ;
146
146
}
147
- else if ( fieldType . ElementType == Internal . Runtime . EETypeElementType . Double )
147
+ else if ( fieldType -> ElementType == EETypeElementType . Double )
148
148
{
149
149
hashCode = Unsafe . As < byte , double > ( ref fieldData ) . GetHashCode ( ) ;
150
150
}
151
- else if ( fieldType . IsPrimitive )
151
+ else if ( fieldType -> IsPrimitive )
152
152
{
153
153
hashCode = FastGetValueTypeHashCodeHelper ( fieldType , ref fieldData ) ;
154
154
}
155
- else if ( fieldType . IsValueType )
155
+ else if ( fieldType -> IsValueType )
156
156
{
157
157
// We have no option but to box since this value type could have
158
158
// GC pointers (we could find out if we want though), or fields of type Double/Single (we can't
0 commit comments