From 7da7d6c46812c3050a634021d887e97211fd8223 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 2 Oct 2018 16:28:29 +0200 Subject: [PATCH] Do not use length if we can pattern match (#5716) * Do not use length if we can pattern match * Check field count only once --- src/fsharp/NameResolution.fs | 3 +-- src/fsharp/TypeChecker.fs | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fsharp/NameResolution.fs b/src/fsharp/NameResolution.fs index a53b1f0a939..bc0a24aa47b 100644 --- a/src/fsharp/NameResolution.fs +++ b/src/fsharp/NameResolution.fs @@ -430,8 +430,7 @@ let private GetCSharpStyleIndexedExtensionMembersForTyconRef (amap:Import.Import // Method must be static, have 'Extension' attribute, must not be curried, must have at least one argument if not minfo.IsInstance && not minfo.IsExtensionMember && - minfo.NumArgs.Length = 1 && - minfo.NumArgs.Head >= 1 && + (match minfo.NumArgs with [x] when x >= 1 -> true | _ -> false) && MethInfoHasAttribute g m g.attrib_ExtensionAttribute minfo then let ilExtMem = ILExtMem (tcrefOfStaticClass, minfo, pri) diff --git a/src/fsharp/TypeChecker.fs b/src/fsharp/TypeChecker.fs index d579e149a95..ce32ded1c6c 100755 --- a/src/fsharp/TypeChecker.fs +++ b/src/fsharp/TypeChecker.fs @@ -1941,6 +1941,7 @@ let FreshenAbstractSlot g amap m synTyparDecls absMethInfo = let BuildFieldMap cenv env isPartial ty flds m = let ad = env.eAccessRights if isNil flds then invalidArg "flds" "BuildFieldMap" + let fldCount = flds.Length let frefSets = let allFields = flds |> List.map (fun ((_, ident), _) -> ident) @@ -1960,7 +1961,7 @@ let BuildFieldMap cenv env isPartial ty flds m = warning (Error(FSComp.SR.tcFieldsDoNotDetermineUniqueRecordType(), m)) // try finding a record type with the same number of fields as the ones that are given. - match tcrefs |> List.tryFind (fun tc -> tc.TrueFieldsAsList.Length = flds.Length) with + match tcrefs |> List.tryFind (fun tc -> tc.TrueFieldsAsList.Length = fldCount) with | Some tcref -> tcref | _ -> // OK, there isn't a unique, good type dictated by the intersection for the field refs.