From a2c264c2da2b4fa1c618cc212aa91c60864254d2 Mon Sep 17 00:00:00 2001 From: Mecu Sorin Date: Fri, 23 Oct 2020 10:34:01 +0300 Subject: [PATCH] Small optimization to compute the elements idf just n times, not n * (n + 1) times. --- src/fsharp/CheckDeclarations.fs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/fsharp/CheckDeclarations.fs b/src/fsharp/CheckDeclarations.fs index 5ec8ff9c352..50e3e1a0292 100644 --- a/src/fsharp/CheckDeclarations.fs +++ b/src/fsharp/CheckDeclarations.fs @@ -381,15 +381,13 @@ let CheckNamespaceModuleOrTypeName (g: TcGlobals) (id: Ident) = errorR(Error(FSComp.SR.tcInvalidNamespaceModuleTypeUnionName(), id.idRange)) let CheckDuplicates (idf: _ -> Ident) k elems = - elems |> List.iteri (fun i uc1 -> - elems |> List.iteri (fun j uc2 -> - let id1 = (idf uc1) - let id2 = (idf uc2) + let ids = elems |> List.mapi (fun i uc -> i, idf uc) + for (i, id1) in ids do + for (j, id2) in ids do if j > i && id1.idText = id2.idText then - errorR (Duplicate(k, id1.idText, id1.idRange)))) + errorR (Duplicate(k, id1.idText, id1.idRange)) elems - module TcRecdUnionAndEnumDeclarations = let CombineReprAccess parent vis =