Skip to content

Commit 5085029

Browse files
forkibaronfel
authored andcommitted
Avoid allocating in IsOperatorName (#7061)
* Avoid allocating in IsOperatorName * bring back Ordinal * flip bool
1 parent 1b793e0 commit 5085029

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/fsharp/ErrorResolutionHints.fs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@ let FilterPredictions (suggestionF:ErrorLogger.Suggestions) (idText:string) =
3636

3737
/// Returns `true` if given string is an operator display name, e.g. ( |>> )
3838
let IsOperatorName (name: string) =
39-
if not (name.StartsWithOrdinal("( ") && name.EndsWithOrdinal(" )")) then
39+
if isNull name || not (name.StartsWithOrdinal("( ") && name.EndsWithOrdinal(" )")) then
4040
false
4141
else
42-
let name = name.[2..name.Length - 3]
43-
name |> Seq.forall (fun c -> c <> ' ')
42+
let mutable i = 2
43+
let mutable isOperator = true
44+
while isOperator && i < name.Length - 3 do
45+
if name.[i] = ' ' then
46+
isOperator <- false
47+
i <- i + 1
48+
isOperator
4449

4550
if allSuggestions.Contains idText then [] else // some other parsing error occurred
4651
let dotIdText = "." + idText

0 commit comments

Comments
 (0)