@@ -798,14 +798,17 @@ private unsafe SortKey CreateSortKey(string source, CompareOptions options)
798
798
}
799
799
else
800
800
{
801
- int sortKeyLength = Interop . Globalization . GetSortKey ( _sortHandle , source , source . Length , null , 0 , options ) ;
802
- keyData = new byte [ sortKeyLength ] ;
803
-
804
- fixed ( byte * pSortKey = keyData )
801
+ fixed ( char * pSource = source )
805
802
{
806
- if ( Interop . Globalization . GetSortKey ( _sortHandle , source , source . Length , pSortKey , sortKeyLength , options ) != sortKeyLength )
803
+ int sortKeyLength = Interop . Globalization . GetSortKey ( _sortHandle , pSource , source . Length , null , 0 , options ) ;
804
+ keyData = new byte [ sortKeyLength ] ;
805
+
806
+ fixed ( byte * pSortKey = keyData )
807
807
{
808
- throw new ArgumentException ( SR . Arg_ExternalException ) ;
808
+ if ( Interop . Globalization . GetSortKey ( _sortHandle , pSource , source . Length , pSortKey , sortKeyLength , options ) != sortKeyLength )
809
+ {
810
+ throw new ArgumentException ( SR . Arg_ExternalException ) ;
811
+ }
809
812
}
810
813
}
811
814
}
@@ -856,42 +859,43 @@ private static unsafe bool IsSortable(char *text, int length)
856
859
// ---- PAL layer ends here ----
857
860
// -----------------------------
858
861
859
- internal unsafe int GetHashCodeOfStringCore ( string source , CompareOptions options )
862
+ internal unsafe int GetHashCodeOfStringCore ( ReadOnlySpan < char > source , CompareOptions options )
860
863
{
861
864
Debug . Assert ( ! _invariantMode ) ;
862
-
863
- Debug . Assert ( source != null ) ;
864
865
Debug . Assert ( ( options & ( CompareOptions . Ordinal | CompareOptions . OrdinalIgnoreCase ) ) == 0 ) ;
865
866
866
867
if ( source . Length == 0 )
867
868
{
868
869
return 0 ;
869
870
}
870
871
871
- int sortKeyLength = Interop . Globalization . GetSortKey ( _sortHandle , source , source . Length , null , 0 , options ) ;
872
+ fixed ( char * pSource = source )
873
+ {
874
+ int sortKeyLength = Interop . Globalization . GetSortKey ( _sortHandle , pSource , source . Length , null , 0 , options ) ;
872
875
873
- byte [ ] borrowedArr = null ;
874
- Span < byte > span = sortKeyLength <= 512 ?
875
- stackalloc byte [ 512 ] :
876
- ( borrowedArr = ArrayPool < byte > . Shared . Rent ( sortKeyLength ) ) ;
876
+ byte [ ] borrowedArr = null ;
877
+ Span < byte > span = sortKeyLength <= 512 ?
878
+ stackalloc byte [ 512 ] :
879
+ ( borrowedArr = ArrayPool < byte > . Shared . Rent ( sortKeyLength ) ) ;
877
880
878
- fixed ( byte * pSortKey = & MemoryMarshal . GetReference ( span ) )
879
- {
880
- if ( Interop . Globalization . GetSortKey ( _sortHandle , source , source . Length , pSortKey , sortKeyLength , options ) != sortKeyLength )
881
+ fixed ( byte * pSortKey = & MemoryMarshal . GetReference ( span ) )
881
882
{
882
- throw new ArgumentException ( SR . Arg_ExternalException ) ;
883
+ if ( Interop . Globalization . GetSortKey ( _sortHandle , pSource , source . Length , pSortKey , sortKeyLength , options ) != sortKeyLength )
884
+ {
885
+ throw new ArgumentException ( SR . Arg_ExternalException ) ;
886
+ }
883
887
}
884
- }
885
888
886
- int hash = Marvin . ComputeHash32 ( span . Slice ( 0 , sortKeyLength ) , Marvin . DefaultSeed ) ;
889
+ int hash = Marvin . ComputeHash32 ( span . Slice ( 0 , sortKeyLength ) , Marvin . DefaultSeed ) ;
887
890
888
- // Return the borrowed array if necessary.
889
- if ( borrowedArr != null )
890
- {
891
- ArrayPool < byte > . Shared . Return ( borrowedArr ) ;
892
- }
891
+ // Return the borrowed array if necessary.
892
+ if ( borrowedArr != null )
893
+ {
894
+ ArrayPool < byte > . Shared . Return ( borrowedArr ) ;
895
+ }
893
896
894
- return hash ;
897
+ return hash ;
898
+ }
895
899
}
896
900
897
901
private static CompareOptions GetOrdinalCompareOptions ( CompareOptions options )
0 commit comments