@@ -20,7 +20,7 @@ internal static class TupleLayout
20
20
21
21
private const int Val064BitCount = 1 << Val064Rank ;
22
22
23
- private ref struct Counters
23
+ internal ref struct Counters
24
24
{
25
25
public int ObjectCounter ;
26
26
@@ -107,13 +107,11 @@ ValueFieldAccessor ResolveByNullableType(Type type)
107
107
}
108
108
}
109
109
110
- private delegate void CounterIncrementer ( ref Counters counters ) ;
110
+ internal delegate void CounterIncrementer ( ref Counters counters ) ;
111
111
112
- private delegate void PositionUpdater ( ref PackedFieldDescriptor descriptor , ref Counters counters ) ;
112
+ internal delegate void PositionUpdater ( ref PackedFieldDescriptor descriptor , ref Counters counters ) ;
113
113
114
114
private static readonly ObjectFieldAccessor ObjectAccessor = new ObjectFieldAccessor ( ) ;
115
- private static readonly CounterIncrementer [ ] IncrementerByRank ;
116
- private static readonly PositionUpdater [ ] PositionUpdaterByRank ;
117
115
118
116
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
119
117
public static void ConfigureFieldAccessor ( ref PackedFieldDescriptor descriptor , Type fieldType ) =>
@@ -218,76 +216,31 @@ public static void Configure(Type[] fieldTypes, PackedFieldDescriptor[] fieldDes
218
216
219
217
for ( var fieldIndex = 0 ; fieldIndex < fieldCount ; fieldIndex ++ ) {
220
218
ref var descriptor = ref fieldDescriptors [ fieldIndex ] ;
221
- if ( descriptor . IsObjectField ( ) ) {
222
- continue ;
219
+ if ( ! descriptor . IsObjectField ( ) ) {
220
+ descriptor . GetAccessor ( ) . PositionUpdater ( ref descriptor , ref counters ) ;
223
221
}
224
-
225
- PositionUpdaterByRank [ descriptor . GetAccessor ( ) . Rank ] . Invoke ( ref descriptor , ref counters ) ;
226
222
}
227
223
228
224
valuesLength = ( totalBitCount + ( Val064BitCount - 1 ) ) >> Val064Rank ;
229
225
objectsLength = counters . ObjectCounter ;
230
226
}
231
227
232
- [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
233
- private static void UpdateDescriptorPosition ( ref PackedFieldDescriptor descriptor , ref int bitCounter )
234
- {
235
- descriptor . DataPosition = bitCounter ;
236
- bitCounter += descriptor . GetAccessor ( ) . ValueBitCount ;
237
- }
238
-
239
228
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
240
229
private static void ConfigureFieldPhase1 ( ref PackedFieldDescriptor descriptor , ref Counters counters ,
241
230
Type [ ] fieldTypes , int fieldIndex )
242
231
{
243
232
descriptor . StatePosition = checked ( ( ushort ) ( fieldIndex << 1 ) ) ;
244
233
245
234
ref var fieldType = ref fieldTypes [ fieldIndex ] ;
246
- var valueAccessor = ValueFieldAccessorResolver . GetValue ( fieldType ) ;
247
- if ( valueAccessor != null ) {
235
+ if ( ValueFieldAccessorResolver . GetValue ( fieldType ) is { } valueAccessor ) {
248
236
descriptor . AccessorIndex = valueAccessor . Index ;
249
-
250
- IncrementerByRank [ valueAccessor . Rank ] . Invoke ( ref counters ) ;
251
-
237
+ valueAccessor . CounterIncrementer ( ref counters ) ;
252
238
fieldType = valueAccessor . FieldType ;
253
239
return ;
254
240
}
255
241
256
242
descriptor . AccessorIndex = ObjectAccessor . Index ;
257
243
descriptor . DataPosition = counters . ObjectCounter ++ ;
258
244
}
259
-
260
- static TupleLayout ( )
261
- {
262
- IncrementerByRank = new CounterIncrementer [ ] {
263
- ( ref Counters counters ) => counters . Val001Counter ++ ,
264
- ( ref Counters counters ) => throw new NotSupportedException ( ) ,
265
- ( ref Counters counters ) => throw new NotSupportedException ( ) ,
266
- ( ref Counters counters ) => counters . Val008Counter ++ ,
267
- ( ref Counters counters ) => counters . Val016Counter ++ ,
268
- ( ref Counters counters ) => counters . Val032Counter ++ ,
269
- ( ref Counters counters ) => counters . Val064Counter ++ ,
270
- ( ref Counters counters ) => counters . Val128Counter ++
271
- } ;
272
-
273
- PositionUpdaterByRank = new PositionUpdater [ ] {
274
- ( ref PackedFieldDescriptor descriptor , ref Counters counters )
275
- => UpdateDescriptorPosition ( ref descriptor , ref counters . Val001Counter ) ,
276
- ( ref PackedFieldDescriptor descriptor , ref Counters counters )
277
- => throw new NotSupportedException ( ) ,
278
- ( ref PackedFieldDescriptor descriptor , ref Counters counters )
279
- => throw new NotSupportedException ( ) ,
280
- ( ref PackedFieldDescriptor descriptor , ref Counters counters )
281
- => UpdateDescriptorPosition ( ref descriptor , ref counters . Val008Counter ) ,
282
- ( ref PackedFieldDescriptor descriptor , ref Counters counters )
283
- => UpdateDescriptorPosition ( ref descriptor , ref counters . Val016Counter ) ,
284
- ( ref PackedFieldDescriptor descriptor , ref Counters counters )
285
- => UpdateDescriptorPosition ( ref descriptor , ref counters . Val032Counter ) ,
286
- ( ref PackedFieldDescriptor descriptor , ref Counters counters )
287
- => UpdateDescriptorPosition ( ref descriptor , ref counters . Val064Counter ) ,
288
- ( ref PackedFieldDescriptor descriptor , ref Counters counters )
289
- => UpdateDescriptorPosition ( ref descriptor , ref counters . Val128Counter )
290
- } ;
291
- }
292
245
}
293
246
}
0 commit comments