File tree Expand file tree Collapse file tree 1 file changed +7
-14
lines changed
Microsoft.Toolkit.HighPerformance/Helpers/Internals Expand file tree Collapse file tree 1 file changed +7
-14
lines changed Original file line number Diff line number Diff line change @@ -32,31 +32,24 @@ internal static class RuntimeHelpers
32
32
/// <returns>The converted length for the specified argument and types.</returns>
33
33
[ Pure ]
34
34
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
35
- public static int ConvertLength < TFrom , TTo > ( int length )
35
+ public static unsafe int ConvertLength < TFrom , TTo > ( int length )
36
36
where TFrom : unmanaged
37
37
where TTo : unmanaged
38
38
{
39
- uint fromSize = ( uint ) Unsafe . SizeOf < TFrom > ( ) ;
40
- uint toSize = ( uint ) Unsafe . SizeOf < TTo > ( ) ;
41
- uint fromLength = ( uint ) length ;
42
- int toLength ;
43
-
44
- if ( fromSize == toSize )
39
+ if ( sizeof ( TFrom ) == sizeof ( TTo ) )
45
40
{
46
- toLength = ( int ) fromLength ;
41
+ return length ;
47
42
}
48
- else if ( fromSize == 1 )
43
+ else if ( sizeof ( TFrom ) == 1 )
49
44
{
50
- toLength = ( int ) ( fromLength / toSize ) ;
45
+ return length / sizeof ( TTo ) ;
51
46
}
52
47
else
53
48
{
54
- ulong toLengthUInt64 = ( ulong ) fromLength * fromSize / toSize ;
49
+ ulong targetLength = ( ulong ) ( uint ) length * ( uint ) sizeof ( TFrom ) / ( uint ) sizeof ( TTo ) ;
55
50
56
- toLength = checked ( ( int ) toLengthUInt64 ) ;
51
+ return checked ( ( int ) targetLength ) ;
57
52
}
58
-
59
- return toLength ;
60
53
}
61
54
62
55
/// <summary>
You can’t perform that action at this time.
0 commit comments