@@ -3605,12 +3605,12 @@ public IConfiguration To<T1, T2, T3, T4, T5, T6, T7, T8, T>(Func<T1, T2, T3, T4,
36053605 [ global ::System . Diagnostics . CodeAnalysis . ExcludeFromCodeCoverage ]
36063606#endif
36073607 [ global ::System . Runtime . InteropServices . StructLayout ( global ::System . Runtime . InteropServices . LayoutKind . Sequential , Pack = 1 ) ]
3608- internal struct Pair < TKey , TValue >
3608+ internal struct Pair < TValue >
36093609 {
3610- public readonly TKey Key ;
3610+ public readonly global :: System . Type Key ;
36113611 public readonly TValue Value ;
36123612
3613- public Pair ( TKey key , TValue value )
3613+ public Pair ( global :: System . Type key , TValue value )
36143614 {
36153615 Key = key ;
36163616 Value = value ;
@@ -3628,39 +3628,43 @@ public override string ToString()
36283628#if ! NET20 && ! NET35 && ! NETSTANDARD1_0 && ! NETSTANDARD1_1 && ! NETSTANDARD1_2 && ! NETSTANDARD1_3 && ! NETSTANDARD1_4 && ! NETSTANDARD1_5 && ! NETSTANDARD1_6 && ! NETCOREAPP1_0 && ! NETCOREAPP1_1
36293629 [ global ::System . Diagnostics . CodeAnalysis . ExcludeFromCodeCoverage ]
36303630#endif
3631- internal static class Buckets < TKey , TValue >
3631+ internal static class Buckets < TValue >
36323632 {
36333633 [ global ::System . Runtime . CompilerServices . MethodImpl ( ( global ::System . Runtime . CompilerServices . MethodImplOptions ) 256 ) ]
36343634 public static uint GetDivisor ( uint count )
36353635 {
36363636 return count < 2 ? count : count << 1 ;
36373637 }
36383638
3639- public static Pair < TKey , TValue > [ ] Create (
3639+ public static Pair < TValue > [ ] Create (
36403640 uint divisor ,
3641- out int bucketSize ,
3642- Pair < TKey , TValue > [ ] pairs )
3641+ out uint bucketSize ,
3642+ Pair < TValue > [ ] pairs )
36433643 {
36443644 bucketSize = 0 ;
3645- int [ ] bucketSizes = new int [ divisor ] ;
3646- for ( int i = 0 ; i < pairs . Length ; i ++ )
3645+ #if NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER
3646+ global ::System . Span < uint > bucketSizes = divisor < 0x1000 ? stackalloc uint [ ( int ) divisor ] : new uint [ divisor ] ;
3647+ #else
3648+ var bucketSizes = new uint [ divisor ] ;
3649+ #endif
3650+ for ( var i = 0 ; i < pairs . Length ; i ++ )
36473651 {
3648- int bucket = ( int ) ( ( ( uint ) global ::System . Runtime . CompilerServices . RuntimeHelpers . GetHashCode ( pairs [ i ] . Key ) ) % divisor ) ;
3649- int size = bucketSizes [ bucket ] + 1 ;
3650- bucketSizes [ bucket ] = size ;
3651- if ( size > bucketSize )
3652+ var bucket = ( int ) ( ( ( uint ) global ::System . Runtime . CompilerServices . RuntimeHelpers . GetHashCode ( pairs [ i ] . Key ) ) % divisor ) ;
3653+ ref var size = ref bucketSizes [ bucket ] ;
3654+ if ( ++ size > bucketSize )
36523655 {
36533656 bucketSize = size ;
36543657 }
36553658 }
36563659
3657- Pair < TKey , TValue > [ ] buckets = new Pair < TKey , TValue > [ divisor * bucketSize ] ;
3658- for ( int i = 0 ; i < pairs . Length ; i ++ )
3660+ var buckets = new Pair < TValue > [ divisor * bucketSize ] ;
3661+ for ( var i = 0 ; i < pairs . Length ; i ++ )
36593662 {
3660- int bucket = ( int ) ( ( ( uint ) global ::System . Runtime . CompilerServices . RuntimeHelpers . GetHashCode ( pairs [ i ] . Key ) ) % divisor ) ;
3661- var index = bucketSizes [ bucket ] ;
3662- buckets [ bucket * bucketSize + bucketSize - index ] = pairs [ i ] ;
3663- bucketSizes [ bucket ] = index - 1 ;
3663+ ref var pair = ref pairs [ i ] ;
3664+ var bucket = ( int ) ( ( ( uint ) global ::System . Runtime . CompilerServices . RuntimeHelpers . GetHashCode ( pair . Key ) ) % divisor ) ;
3665+ ref var index = ref bucketSizes [ bucket ++ ] ;
3666+ buckets [ bucket * bucketSize - index ] = pair ;
3667+ index -- ;
36643668 }
36653669
36663670 return buckets ;
0 commit comments