@@ -2018,8 +2018,8 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)
2018
2018
/// <returns>A 32-bit signed integer hash code.</returns>
2019
2019
public override int GetHashCode ( )
2020
2020
{
2021
- // We want to have a limited hash in this case. We'll use the last 8 elements of the tuple
2022
- if ( ! ( Rest is IValueTupleInternal rest ) )
2021
+ // We want to have a limited hash in this case. We'll use the first 7 elements of the tuple
2022
+ if ( ! ( Rest is IValueTupleInternal ) )
2023
2023
{
2024
2024
return HashCode . Combine ( Item1 ? . GetHashCode ( ) ?? 0 ,
2025
2025
Item2 ? . GetHashCode ( ) ?? 0 ,
@@ -2030,46 +2030,50 @@ public override int GetHashCode()
2030
2030
Item7 ? . GetHashCode ( ) ?? 0 ) ;
2031
2031
}
2032
2032
2033
- int size = rest . Length ;
2034
- if ( size >= 8 ) { return rest . GetHashCode ( ) ; }
2033
+ int size = ( ( IValueTupleInternal ) Rest ) . Length ;
2034
+ int restHashCode = Rest . GetHashCode ( ) ;
2035
+ if ( size >= 8 )
2036
+ {
2037
+ return restHashCode ;
2038
+ }
2035
2039
2036
- // In this case, the rest member has less than 8 elements so we need to combine some our elements with the elements in rest
2040
+ // In this case, the rest member has less than 8 elements so we need to combine some of our elements with the elements in rest
2037
2041
int k = 8 - size ;
2038
2042
switch ( k )
2039
2043
{
2040
2044
case 1 :
2041
2045
return HashCode . Combine ( Item7 ? . GetHashCode ( ) ?? 0 ,
2042
- rest . GetHashCode ( ) ) ;
2046
+ restHashCode ) ;
2043
2047
case 2 :
2044
2048
return HashCode . Combine ( Item6 ? . GetHashCode ( ) ?? 0 ,
2045
2049
Item7 ? . GetHashCode ( ) ?? 0 ,
2046
- rest . GetHashCode ( ) ) ;
2050
+ restHashCode ) ;
2047
2051
case 3 :
2048
2052
return HashCode . Combine ( Item5 ? . GetHashCode ( ) ?? 0 ,
2049
2053
Item6 ? . GetHashCode ( ) ?? 0 ,
2050
2054
Item7 ? . GetHashCode ( ) ?? 0 ,
2051
- rest . GetHashCode ( ) ) ;
2055
+ restHashCode ) ;
2052
2056
case 4 :
2053
2057
return HashCode . Combine ( Item4 ? . GetHashCode ( ) ?? 0 ,
2054
2058
Item5 ? . GetHashCode ( ) ?? 0 ,
2055
2059
Item6 ? . GetHashCode ( ) ?? 0 ,
2056
2060
Item7 ? . GetHashCode ( ) ?? 0 ,
2057
- rest . GetHashCode ( ) ) ;
2061
+ restHashCode ) ;
2058
2062
case 5 :
2059
2063
return HashCode . Combine ( Item3 ? . GetHashCode ( ) ?? 0 ,
2060
2064
Item4 ? . GetHashCode ( ) ?? 0 ,
2061
2065
Item5 ? . GetHashCode ( ) ?? 0 ,
2062
2066
Item6 ? . GetHashCode ( ) ?? 0 ,
2063
2067
Item7 ? . GetHashCode ( ) ?? 0 ,
2064
- rest . GetHashCode ( ) ) ;
2068
+ restHashCode ) ;
2065
2069
case 6 :
2066
2070
return HashCode . Combine ( Item2 ? . GetHashCode ( ) ?? 0 ,
2067
2071
Item3 ? . GetHashCode ( ) ?? 0 ,
2068
2072
Item4 ? . GetHashCode ( ) ?? 0 ,
2069
2073
Item5 ? . GetHashCode ( ) ?? 0 ,
2070
2074
Item6 ? . GetHashCode ( ) ?? 0 ,
2071
2075
Item7 ? . GetHashCode ( ) ?? 0 ,
2072
- rest . GetHashCode ( ) ) ;
2076
+ restHashCode ) ;
2073
2077
case 7 :
2074
2078
case 8 :
2075
2079
return HashCode . Combine ( Item1 ? . GetHashCode ( ) ?? 0 ,
@@ -2079,7 +2083,7 @@ public override int GetHashCode()
2079
2083
Item5 ? . GetHashCode ( ) ?? 0 ,
2080
2084
Item6 ? . GetHashCode ( ) ?? 0 ,
2081
2085
Item7 ? . GetHashCode ( ) ?? 0 ,
2082
- rest . GetHashCode ( ) ) ;
2086
+ restHashCode ) ;
2083
2087
}
2084
2088
2085
2089
Debug . Fail ( "Missed all cases for computing ValueTuple hash code" ) ;
@@ -2093,7 +2097,7 @@ int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
2093
2097
2094
2098
private int GetHashCodeCore ( IEqualityComparer comparer )
2095
2099
{
2096
- // We want to have a limited hash in this case. We'll use the last 8 elements of the tuple
2100
+ // We want to have a limited hash in this case. We'll use the first 7 elements of the tuple
2097
2101
if ( ! ( Rest is IValueTupleInternal rest ) )
2098
2102
{
2099
2103
return HashCode . Combine ( comparer . GetHashCode ( Item1 ! ) , comparer . GetHashCode ( Item2 ! ) , comparer . GetHashCode ( Item3 ! ) ,
@@ -2151,19 +2155,19 @@ int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
2151
2155
/// </remarks>
2152
2156
public override string ToString ( )
2153
2157
{
2154
- if ( Rest is IValueTupleInternal rest )
2158
+ if ( Rest is IValueTupleInternal )
2155
2159
{
2156
- return "(" + Item1 ? . ToString ( ) + ", " + Item2 ? . ToString ( ) + ", " + Item3 ? . ToString ( ) + ", " + Item4 ? . ToString ( ) + ", " + Item5 ? . ToString ( ) + ", " + Item6 ? . ToString ( ) + ", " + Item7 ? . ToString ( ) + ", " + rest . ToStringEnd ( ) ;
2160
+ return "(" + Item1 ? . ToString ( ) + ", " + Item2 ? . ToString ( ) + ", " + Item3 ? . ToString ( ) + ", " + Item4 ? . ToString ( ) + ", " + Item5 ? . ToString ( ) + ", " + Item6 ? . ToString ( ) + ", " + Item7 ? . ToString ( ) + ", " + ( ( IValueTupleInternal ) Rest ) . ToStringEnd ( ) ;
2157
2161
}
2158
2162
2159
2163
return "(" + Item1 ? . ToString ( ) + ", " + Item2 ? . ToString ( ) + ", " + Item3 ? . ToString ( ) + ", " + Item4 ? . ToString ( ) + ", " + Item5 ? . ToString ( ) + ", " + Item6 ? . ToString ( ) + ", " + Item7 ? . ToString ( ) + ", " + Rest . ToString ( ) + ")" ;
2160
2164
}
2161
2165
2162
2166
string IValueTupleInternal . ToStringEnd ( )
2163
2167
{
2164
- if ( Rest is IValueTupleInternal rest )
2168
+ if ( Rest is IValueTupleInternal )
2165
2169
{
2166
- return Item1 ? . ToString ( ) + ", " + Item2 ? . ToString ( ) + ", " + Item3 ? . ToString ( ) + ", " + Item4 ? . ToString ( ) + ", " + Item5 ? . ToString ( ) + ", " + Item6 ? . ToString ( ) + ", " + Item7 ? . ToString ( ) + ", " + rest . ToStringEnd ( ) ;
2170
+ return Item1 ? . ToString ( ) + ", " + Item2 ? . ToString ( ) + ", " + Item3 ? . ToString ( ) + ", " + Item4 ? . ToString ( ) + ", " + Item5 ? . ToString ( ) + ", " + Item6 ? . ToString ( ) + ", " + Item7 ? . ToString ( ) + ", " + ( ( IValueTupleInternal ) Rest ) . ToStringEnd ( ) ;
2167
2171
}
2168
2172
2169
2173
return Item1 ? . ToString ( ) + ", " + Item2 ? . ToString ( ) + ", " + Item3 ? . ToString ( ) + ", " + Item4 ? . ToString ( ) + ", " + Item5 ? . ToString ( ) + ", " + Item6 ? . ToString ( ) + ", " + Item7 ? . ToString ( ) + ", " + Rest . ToString ( ) + ")" ;
@@ -2172,7 +2176,7 @@ string IValueTupleInternal.ToStringEnd()
2172
2176
/// <summary>
2173
2177
/// The number of positions in this data structure.
2174
2178
/// </summary>
2175
- int ITuple . Length => Rest is IValueTupleInternal rest ? 7 + rest . Length : 8 ;
2179
+ int ITuple . Length => Rest is IValueTupleInternal ? 7 + ( ( IValueTupleInternal ) Rest ) . Length : 8 ;
2176
2180
2177
2181
/// <summary>
2178
2182
/// Get the element at position <param name="index"/>.
@@ -2199,9 +2203,9 @@ string IValueTupleInternal.ToStringEnd()
2199
2203
return Item7 ;
2200
2204
}
2201
2205
2202
- if ( Rest is IValueTupleInternal rest )
2206
+ if ( Rest is IValueTupleInternal )
2203
2207
{
2204
- return rest [ index - 7 ] ;
2208
+ return ( ( IValueTupleInternal ) Rest ) [ index - 7 ] ;
2205
2209
}
2206
2210
2207
2211
0 commit comments