@@ -1235,15 +1235,15 @@ let getEnumerator com r t i (expr: Expr) =
12351235 makeInstanceCall r t i expr " GetEnumerator" []
12361236
12371237let strings ( com : ICompiler ) ( ctx : Context ) r t ( i : CallInfo ) ( thisArg : Expr option ) ( args : Expr list ) =
1238- let isIgnoreCase args =
1239- match args with
1240- | [] -> false
1241- | [ BoolConst ignoreCase ] -> ignoreCase
1242- | [ BoolConst ignoreCase; _ cultureInfo ] -> ignoreCase
1243- | [ NumberConst( NumberValue.Int32 kind, NumberInfo.IsEnum _) ] -> kind = 1 || kind = 3 || kind = 5
1244- | [ _ cultureInfo; NumberConst( NumberValue.Int32 options, NumberInfo.IsEnum _) ] ->
1245- ( options &&& 1 <> 0 ) || ( options &&& 268435456 <> 0 )
1246- | _ -> false
1238+ // let isIgnoreCase args =
1239+ // match args with
1240+ // | [] -> false
1241+ // | [ BoolConst ignoreCase ] -> ignoreCase
1242+ // | [ BoolConst ignoreCase; _cultureInfo ] -> ignoreCase
1243+ // | [ NumberConst(NumberValue.Int32 kind, NumberInfo.IsEnum _) ] -> kind = 1 || kind = 3 || kind = 5
1244+ // | [ _cultureInfo; NumberConst(NumberValue.Int32 options, NumberInfo.IsEnum _) ] ->
1245+ // (options &&& 1 <> 0) || (options &&& 268435456 <> 0)
1246+ // | _ -> false
12471247
12481248 match i.CompiledName, thisArg, args with
12491249 | " .ctor" , _, _ ->
@@ -1255,28 +1255,44 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt
12551255 | _ -> None
12561256 | " get_Length" , Some c, _ -> Helper.LibCall( com, " String" , " length" , t, c :: args, ?loc = r) |> Some
12571257 | " get_Chars" , Some c, _ -> Helper.LibCall( com, " String" , " getCharAt" , t, c :: args, ?loc = r) |> Some
1258- | ( " Compare" | " CompareOrdinal" ), None, _ ->
1259- if i.CompiledName = " Compare" then
1260- $" String.Compare will be compiled as String.CompareOrdinal"
1261- |> addWarning com ctx.InlinePath r
1262-
1258+ | " CompareOrdinal" , None, _ ->
12631259 match args with
1264- | ExprType String :: ExprType String :: restArgs ->
1265- let args = ( args |> List.take 2 ) @ [ makeBoolConst ( isIgnoreCase restArgs) ]
1266-
1260+ | [ ExprType String; ExprType String ] ->
12671261 Helper.LibCall( com, " String" , " compareOrdinal" , t, args, ?loc = r) |> Some
1268- | ExprType String :: ExprType( Number ( Int32 , _)) :: ExprType String :: ExprType ( Number ( Int32 , _)) :: ExprType ( Number ( Int32 ,
1269- _)) :: restArgs ->
1270- let args = ( args |> List.take 5 ) @ [ makeBoolConst ( isIgnoreCase restArgs ) ]
1271-
1272- Helper.LibCall( com, " String" , " compareOrdinal2" , t, args, ?loc = r) |> Some
1262+ | [ ExprType String
1263+ ExprType ( Number ( Int32 , _))
1264+ ExprType String
1265+ ExprType ( Number ( Int32 , _))
1266+ ExprType ( Number ( Int32 , _)) ] -> Helper.LibCall( com, " String" , " compareOrdinal2" , t, args, ?loc = r) |> Some
12731267 | _ -> None
12741268 | " CompareTo" , Some c, [ ExprTypeAs( String, arg) ] ->
12751269 $" String.CompareTo will be compiled as String.CompareOrdinal"
12761270 |> addWarning com ctx.InlinePath r
12771271
1278- Helper.LibCall( com, " String" , " compareOrdinal" , t, [ c; arg; makeBoolConst false ], ?loc = r)
1279- |> Some
1272+ Helper.LibCall( com, " String" , " compareOrdinal" , t, [ c; arg ], ?loc = r) |> Some
1273+ | " Compare" , None, _ ->
1274+ $" String.Compare will be compiled as String.CompareOrdinal"
1275+ |> addWarning com ctx.InlinePath r
1276+
1277+ match args with
1278+ | [ ExprType String; ExprType String ] ->
1279+ Helper.LibCall( com, " String" , " compareOrdinal" , t, args, ?loc = r) |> Some
1280+ | ExprType String :: ExprType String :: ExprType Boolean :: restArgs ->
1281+ Helper.LibCall( com, " String" , " compareCase" , t, args, ?loc = r) |> Some
1282+ | [ ExprType String; ExprType String; comparison ] ->
1283+ Helper.LibCall( com, " String" , " compareWith" , t, args, ?loc = r) |> Some
1284+ | [ ExprType String
1285+ ExprType( Number( Int32, _))
1286+ ExprType String
1287+ ExprType( Number( Int32, _))
1288+ ExprType( Number( Int32, _)) ] -> Helper.LibCall( com, " String" , " compareOrdinal2" , t, args, ?loc = r) |> Some
1289+ | ExprType String :: ExprType( Number( Int32, _)) :: ExprType String :: ExprType( Number( Int32, _)) :: ExprType( Number( Int32,
1290+ _)) :: ExprType Boolean :: restArgs ->
1291+ Helper.LibCall( com, " String" , " compareCase2" , t, args, ?loc = r) |> Some
1292+ | ExprType String :: ExprType( Number( Int32, _)) :: ExprType String :: ExprType( Number( Int32, _)) :: ExprType( Number( Int32,
1293+ _)) :: comparison :: restArgs ->
1294+ Helper.LibCall( com, " String" , " compareWith2" , t, args, ?loc = r) |> Some
1295+ | _ -> None
12801296 | " Concat" , None, _ ->
12811297 match args with
12821298 | [ ExprTypeAs( IEnumerable, arg) ] ->
@@ -1292,32 +1308,28 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt
12921308 | " Contains" , Some c, _ ->
12931309 match args with
12941310 | [ ExprType Char ] -> Helper.LibCall( com, " String" , " containsChar" , t, c :: args, ?loc = r) |> Some
1311+ | [ ExprType Char; _ comparison ] ->
1312+ Helper.LibCall( com, " String" , " containsChar2" , t, c :: args, ?loc = r) |> Some
12951313 | [ ExprType String ] -> Helper.LibCall( com, " String" , " contains" , t, c :: args, ?loc = r) |> Some
1314+ | [ ExprType String; _ comparison ] -> Helper.LibCall( com, " String" , " contains2" , t, c :: args, ?loc = r) |> Some
12961315 | _ -> None
12971316 | " EndsWith" , Some c, _ ->
12981317 match args with
12991318 | [ ExprType Char ] -> Helper.LibCall( com, " String" , " endsWithChar" , t, c :: args, ?loc = r) |> Some
1300- | ExprType String :: restArgs ->
1301- let args = ( args |> List.take 1 ) @ [ makeBoolConst ( isIgnoreCase restArgs) ]
1302-
1303- Helper.LibCall( com, " String" , " endsWith" , t, c :: args, ?loc = r) |> Some
1319+ | [ ExprType String ] -> Helper.LibCall( com, " String" , " endsWith" , t, c :: args, ?loc = r) |> Some
1320+ | [ ExprType String; _ comparison ] -> Helper.LibCall( com, " String" , " endsWith2" , t, c :: args, ?loc = r) |> Some
1321+ | [ pattern; ignoreCase; _ culture ] ->
1322+ Helper.LibCall( com, " String" , " endsWith3" , t, [ c; pattern; ignoreCase ], ?loc = r)
1323+ |> Some
13041324 | _ -> None
13051325 | " Equals" , _, _ ->
13061326 match thisArg, args with
13071327 | Some x, [ ExprTypeAs( String, y) ]
13081328 | None, [ ExprTypeAs( String, x); ExprTypeAs( String, y) ] ->
1309- Helper.LibCall( com, " String" , " equalsOrdinal" , t, [ x; y; makeBoolConst false ], ?loc = r)
1310- |> Some
1311- | Some x, [ ExprTypeAs( String, y); NumberConst( NumberValue.Int32 kind, NumberInfo.IsEnum _) ]
1312- | None,
1313- [ ExprTypeAs( String, x); ExprTypeAs( String, y); NumberConst( NumberValue.Int32 kind, NumberInfo.IsEnum _) ] ->
1314- if kind <> 4 && kind <> 5 then
1315- $" String.Equals will be compiled with ordinal equality"
1316- |> addWarning com ctx.InlinePath r
1317-
1318- let ignoreCase = kind = 1 || kind = 3 || kind = 5
1319-
1320- Helper.LibCall( com, " String" , " equalsOrdinal" , t, [ x; y; makeBoolConst ignoreCase ], ?loc = r)
1329+ Helper.LibCall( com, " String" , " equalsOrdinal" , t, [ x; y ], ?loc = r) |> Some
1330+ | Some x, [ ExprTypeAs( String, y); comparison ]
1331+ | None, [ ExprTypeAs( String, x); ExprTypeAs( String, y); comparison ] ->
1332+ Helper.LibCall( com, " String" , " equals2" , t, [ x; y; comparison ], ?loc = r)
13211333 |> Some
13221334 | _ -> None
13231335 | " Format" , None, _ ->
@@ -1487,10 +1499,12 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt
14871499 | " StartsWith" , Some c, _ ->
14881500 match args with
14891501 | [ ExprType Char ] -> Helper.LibCall( com, " String" , " startsWithChar" , t, c :: args, ?loc = r) |> Some
1490- | ExprType String :: restArgs ->
1491- let args = ( args |> List.take 1 ) @ [ makeBoolConst ( isIgnoreCase restArgs) ]
1492-
1493- Helper.LibCall( com, " String" , " startsWith" , t, c :: args, ?loc = r) |> Some
1502+ | [ ExprType String ] -> Helper.LibCall( com, " String" , " startsWith" , t, c :: args, ?loc = r) |> Some
1503+ | [ ExprType String; _ comparison ] ->
1504+ Helper.LibCall( com, " String" , " startsWith2" , t, c :: args, ?loc = r) |> Some
1505+ | [ pattern; ignoreCase; _ culture ] ->
1506+ Helper.LibCall( com, " String" , " startsWith3" , t, [ c; pattern; ignoreCase ], ?loc = r)
1507+ |> Some
14941508 | _ -> None
14951509 | " Substring" , Some c, _ ->
14961510 match args with
0 commit comments