@@ -47,86 +47,74 @@ private static void AssertIndexingSupported(CompareOptions options, string cultu
47
47
private unsafe int JsCompareString ( ReadOnlySpan < char > string1 , ReadOnlySpan < char > string2 , CompareOptions options )
48
48
{
49
49
AssertHybridOnWasm ( options ) ;
50
- string cultureName = m_name ;
51
- AssertComparisonSupported ( options , cultureName ) ;
50
+ AssertComparisonSupported ( options , m_name ) ;
52
51
53
- int cmpResult ;
52
+ ReadOnlySpan < char > cultureNameSpan = m_name . AsSpan ( ) ;
54
53
fixed ( char * pString1 = & MemoryMarshal . GetReference ( string1 ) )
55
54
fixed ( char * pString2 = & MemoryMarshal . GetReference ( string2 ) )
55
+ fixed ( char * pCultureName = & MemoryMarshal . GetReference ( cultureNameSpan ) )
56
56
{
57
- cmpResult = Interop . JsGlobalization . CompareString ( cultureName , pString1 , string1 . Length , pString2 , string2 . Length , options , out int exception , out object ex_result ) ;
58
- if ( exception != 0 )
59
- throw new Exception ( ( string ) ex_result ) ;
57
+ nint exceptionPtr = Interop . JsGlobalization . CompareString ( pCultureName , cultureNameSpan . Length , pString1 , string1 . Length , pString2 , string2 . Length , options , out int cmpResult ) ;
58
+ Helper . MarshalAndThrowIfException ( exceptionPtr ) ;
59
+ return cmpResult ;
60
60
}
61
-
62
- return cmpResult ;
63
61
}
64
62
65
63
private unsafe bool JsStartsWith ( ReadOnlySpan < char > source , ReadOnlySpan < char > prefix , CompareOptions options )
66
64
{
67
65
AssertHybridOnWasm ( options ) ;
68
66
Debug . Assert ( ! prefix . IsEmpty ) ;
69
- string cultureName = m_name ;
70
- AssertIndexingSupported ( options , cultureName ) ;
67
+ AssertIndexingSupported ( options , m_name ) ;
71
68
72
- bool result ;
69
+ ReadOnlySpan < char > cultureNameSpan = m_name . AsSpan ( ) ;
73
70
fixed ( char * pSource = & MemoryMarshal . GetReference ( source ) )
74
71
fixed ( char * pPrefix = & MemoryMarshal . GetReference ( prefix ) )
72
+ fixed ( char * pCultureName = & MemoryMarshal . GetReference ( cultureNameSpan ) )
75
73
{
76
- result = Interop . JsGlobalization . StartsWith ( cultureName , pSource , source . Length , pPrefix , prefix . Length , options , out int exception , out object ex_result ) ;
77
- if ( exception != 0 )
78
- throw new Exception ( ( string ) ex_result ) ;
74
+ nint exceptionPtr = Interop . JsGlobalization . StartsWith ( pCultureName , cultureNameSpan . Length , pSource , source . Length , pPrefix , prefix . Length , options , out bool result ) ;
75
+ Helper . MarshalAndThrowIfException ( exceptionPtr ) ;
76
+ return result ;
79
77
}
80
-
81
-
82
- return result ;
83
78
}
84
79
85
80
private unsafe bool JsEndsWith ( ReadOnlySpan < char > source , ReadOnlySpan < char > prefix , CompareOptions options )
86
81
{
87
82
AssertHybridOnWasm ( options ) ;
88
83
Debug . Assert ( ! prefix . IsEmpty ) ;
89
- string cultureName = m_name ;
90
- AssertIndexingSupported ( options , cultureName ) ;
84
+ AssertIndexingSupported ( options , m_name ) ;
91
85
92
- bool result ;
86
+ ReadOnlySpan < char > cultureNameSpan = m_name . AsSpan ( ) ;
93
87
fixed ( char * pSource = & MemoryMarshal . GetReference ( source ) )
94
88
fixed ( char * pPrefix = & MemoryMarshal . GetReference ( prefix ) )
89
+ fixed ( char * pCultureName = & MemoryMarshal . GetReference ( cultureNameSpan ) )
95
90
{
96
- result = Interop . JsGlobalization . EndsWith ( cultureName , pSource , source . Length , pPrefix , prefix . Length , options , out int exception , out object ex_result ) ;
97
- if ( exception != 0 )
98
- throw new Exception ( ( string ) ex_result ) ;
91
+ nint exceptionPtr = Interop . JsGlobalization . EndsWith ( pCultureName , cultureNameSpan . Length , pSource , source . Length , pPrefix , prefix . Length , options , out bool result ) ;
92
+ Helper . MarshalAndThrowIfException ( exceptionPtr ) ;
93
+ return result ;
99
94
}
100
-
101
- return result ;
102
95
}
103
96
104
97
private unsafe int JsIndexOfCore ( ReadOnlySpan < char > source , ReadOnlySpan < char > target , CompareOptions options , int * matchLengthPtr , bool fromBeginning )
105
98
{
106
99
AssertHybridOnWasm ( options ) ;
107
100
Debug . Assert ( ! target . IsEmpty ) ;
108
- string cultureName = m_name ;
109
- AssertIndexingSupported ( options , cultureName ) ;
101
+ AssertIndexingSupported ( options , m_name ) ;
110
102
111
- int idx ;
112
103
if ( _isAsciiEqualityOrdinal && CanUseAsciiOrdinalForOptions ( options ) )
113
104
{
114
- idx = ( options & CompareOptions . IgnoreCase ) != 0 ?
105
+ return ( options & CompareOptions . IgnoreCase ) != 0 ?
115
106
IndexOfOrdinalIgnoreCaseHelper ( source , target , options , matchLengthPtr , fromBeginning ) :
116
107
IndexOfOrdinalHelper ( source , target , options , matchLengthPtr , fromBeginning ) ;
117
108
}
118
- else
109
+ ReadOnlySpan < char > cultureNameSpan = m_name . AsSpan ( ) ;
110
+ fixed ( char * pSource = & MemoryMarshal . GetReference ( source ) )
111
+ fixed ( char * pTarget = & MemoryMarshal . GetReference ( target ) )
112
+ fixed ( char * pCultureName = & MemoryMarshal . GetReference ( cultureNameSpan ) )
119
113
{
120
- fixed ( char * pSource = & MemoryMarshal . GetReference ( source ) )
121
- fixed ( char * pTarget = & MemoryMarshal . GetReference ( target ) )
122
- {
123
- idx = Interop . JsGlobalization . IndexOf ( m_name , pTarget , target . Length , pSource , source . Length , options , fromBeginning , out int exception , out object ex_result ) ;
124
- if ( exception != 0 )
125
- throw new Exception ( ( string ) ex_result ) ;
126
- }
114
+ nint exceptionPtr = Interop . JsGlobalization . IndexOf ( pCultureName , cultureNameSpan . Length , pTarget , target . Length , pSource , source . Length , options , fromBeginning , out int idx ) ;
115
+ Helper . MarshalAndThrowIfException ( exceptionPtr ) ;
116
+ return idx ;
127
117
}
128
-
129
- return idx ;
130
118
}
131
119
132
120
// there are chars that are ignored by ICU hashing algorithm but not ignored by invariant hashing
0 commit comments