Skip to content

Commit 54cfe95

Browse files
authored
Using Ordinal is both faster and more correct as our intent is to do … (#16439)
* Using Ordinal is both faster and more correct as our intent is to do symbolic compares. * format code * use extension methods
1 parent e9576a2 commit 54cfe95

24 files changed

+53
-32
lines changed

src/Compiler/Checking/CheckFormatStrings.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ let escapeDotnetFormatString str =
5959

6060
[<return: Struct>]
6161
let (|PrefixedBy|_|) (prefix: string) (str: string) =
62-
if str.StartsWith prefix then
62+
if str.StartsWithOrdinal(prefix) then
6363
ValueSome prefix.Length
6464
else
6565
ValueNone
@@ -371,7 +371,7 @@ let parseFormatStringInternal
371371
// type checker. They should always have '(...)' after for format string.
372372
let requireAndSkipInterpolationHoleFormat i =
373373
if i < len && fmt[i] = '(' then
374-
let i2 = fmt.IndexOf(")", i+1)
374+
let i2 = fmt.IndexOfOrdinal(")", i+1)
375375
if i2 = -1 then
376376
failwith (FSComp.SR.forFormatInvalidForInterpolated3())
377377
else

src/Compiler/Checking/ConstraintSolver.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,7 @@ and SolveMemberConstraint (csenv: ConstraintSolverEnv) ignoreUnresolvedOverload
17131713
None
17141714

17151715
let anonRecdPropSearch =
1716-
let isGetProp = nm.StartsWith "get_"
1716+
let isGetProp = nm.StartsWithOrdinal("get_")
17171717
if not isRigid && isGetProp && memFlags.IsInstance then
17181718
let propName = nm[4..]
17191719
let props =

src/Compiler/Checking/MethodCalls.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ type CalledMeth<'T>
538538
// Detect the special case where an indexer setter using param aray takes 'value' argument after ParamArray arguments
539539
let isIndexerSetter =
540540
match pinfoOpt with
541-
| Some pinfo when pinfo.HasSetter && minfo.LogicalName.StartsWith "set_" && (List.concat fullCurriedCalledArgs).Length >= 2 -> true
541+
| Some pinfo when pinfo.HasSetter && minfo.LogicalName.StartsWithOrdinal("set_") && (List.concat fullCurriedCalledArgs).Length >= 2 -> true
542542
| _ -> false
543543

544544
let argSetInfos =

src/Compiler/Checking/NicePrint.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module internal PrintUtilities =
5555

5656
let comment str = wordL (tagText (sprintf "(* %s *)" str))
5757

58-
let isDiscard (name: string) = name.StartsWith("_")
58+
let isDiscard (name: string) = name.StartsWithOrdinal("_")
5959

6060
let ensureFloat (s: string) =
6161
if String.forall (fun c -> Char.IsDigit c || c = '-') s then

src/Compiler/Checking/SignatureHash.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ let calculateHashOfImpliedSignature g observer (expr: ModuleOrNamespaceContents)
476476

477477
let rec hashModuleOrNameSpaceBinding (monb: ModuleOrNamespaceBinding) =
478478
match monb with
479-
| ModuleOrNamespaceBinding.Binding b when b.Var.LogicalName.StartsWith("doval@") -> 0
479+
| ModuleOrNamespaceBinding.Binding b when b.Var.LogicalName.StartsWithOrdinal("doval@") -> 0
480480
| ModuleOrNamespaceBinding.Binding b -> HashTastMemberOrVals.hashValOrMemberNoInst (g, observer) (mkLocalValRef b.Var)
481481
| ModuleOrNamespaceBinding.Module(moduleInfo, contents) -> hashSingleModuleOrNameSpaceIncludingName (moduleInfo, contents)
482482

src/Compiler/Checking/infos.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ type MethInfo =
812812
member x.IsUnionCaseTester =
813813
let tcref = x.ApparentEnclosingTyconRef
814814
tcref.IsUnionTycon &&
815-
x.LogicalName.StartsWith("get_Is") &&
815+
x.LogicalName.StartsWithOrdinal("get_Is") &&
816816
match x.ArbitraryValRef with
817817
| Some v -> v.IsImplied
818818
| None -> false

src/Compiler/CodeGen/IlxGen.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2695,7 +2695,7 @@ let CodeGenThen (cenv: cenv) mgbuf (entryPointInfo, methodName, eenv, alreadyUse
26952695
match selfArgOpt with
26962696
| Some selfArg when
26972697
selfArg.LogicalName <> "this"
2698-
&& not (selfArg.LogicalName.StartsWith("_"))
2698+
&& not (selfArg.LogicalName.StartsWithOrdinal("_"))
26992699
&& not cenv.options.localOptimizationsEnabled
27002700
->
27012701
let ilTy = selfArg.Type |> GenType cenv m eenv.tyenv

src/Compiler/DependencyManager/DependencyProvider.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ type DependencyProvider
612612
let managers =
613613
RegisteredDependencyManagers compilerTools (Option.ofString outputDir) reportError
614614

615-
match managers |> Seq.tryFind (fun kv -> path.StartsWith(kv.Value.Key + ":")) with
615+
match managers |> Seq.tryFind (fun kv -> path.StartsWithOrdinal(kv.Value.Key + ":")) with
616616
| None ->
617617
let err, msg =
618618
this.CreatePackageManagerUnknownError(compilerTools, outputDir, path.Split(':').[0], reportError)

src/Compiler/DependencyManager/NativeDllResolveHandler.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open System.IO
88
open System.Reflection
99
open System.Runtime.InteropServices
1010
open Internal.Utilities
11+
open Internal.Utilities.Library
1112
open Internal.Utilities.FSharpEnvironment
1213
open FSharp.Compiler.IO
1314

@@ -88,7 +89,7 @@ type internal NativeDllResolveHandlerCoreClr(nativeProbingRoots: NativeResolutio
8889
let isRooted = Path.IsPathRooted name
8990

9091
let useSuffix s =
91-
not (name.Contains(s + ".") || name.EndsWith(s)) // linux devs often append version # to libraries I.e mydll.so.5.3.2
92+
not (name.Contains(s + ".") || name.EndsWithOrdinal(s)) // linux devs often append version # to libraries I.e mydll.so.5.3.2
9293

9394
let usePrefix =
9495
name.IndexOf(Path.DirectorySeparatorChar) = -1 // If name has directory information no add no prefix

src/Compiler/Driver/FxResolver.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ type internal FxResolver
238238
dotnetConfig.IndexOf(pattern, StringComparison.OrdinalIgnoreCase)
239239
+ pattern.Length
240240

241-
let endPos = dotnetConfig.IndexOf("\"", startPos)
241+
let endPos = dotnetConfig.IndexOfOrdinal("\"", startPos)
242242
let ver = dotnetConfig[startPos .. endPos - 1]
243243

244244
let path =
@@ -364,7 +364,7 @@ type internal FxResolver
364364
let implDir, warnings = getImplementationAssemblyDir ()
365365
let version = DirectoryInfo(implDir).Name
366366

367-
if version.StartsWith("x") then
367+
if version.StartsWithOrdinal("x") then
368368
// Is running on the desktop
369369
(None, None), warnings
370370
else
@@ -403,7 +403,7 @@ type internal FxResolver
403403
| ".NET", "Core" when arr.Length >= 3 -> Some("netcoreapp" + (getTfmNumber arr[2]))
404404

405405
| ".NET", "Framework" when arr.Length >= 3 ->
406-
if arr[2].StartsWith("4.8") then
406+
if arr[2].StartsWithOrdinal("4.8") then
407407
Some "net48"
408408
else
409409
Some "net472"
@@ -560,7 +560,7 @@ type internal FxResolver
560560
dotnetConfig.IndexOf(pattern, StringComparison.OrdinalIgnoreCase)
561561
+ pattern.Length
562562

563-
let endPos = dotnetConfig.IndexOf("\"", startPos)
563+
let endPos = dotnetConfig.IndexOfOrdinal("\"", startPos)
564564
let tfm = dotnetConfig[startPos .. endPos - 1]
565565
tfm
566566
with _ ->

0 commit comments

Comments
 (0)