Skip to content

Commit bbf07fb

Browse files
forkidsyme
authored andcommitted
List.isEmpty instead of iterating through the list to get the count (#4439)
1 parent e4fb0fc commit bbf07fb

File tree

13 files changed

+46
-48
lines changed

13 files changed

+46
-48
lines changed

src/absil/ilprint.fs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,10 @@ and goutput_typ_with_shortened_class_syntax env os = function
213213
| typ2 -> goutput_typ env os typ2
214214

215215
and goutput_gactuals env os inst =
216-
if inst.Length = 0 then ()
217-
else
218-
output_string os "<";
216+
if not (List.isEmpty inst) then
217+
output_string os "<"
219218
output_seq ", " (goutput_gactual env) os inst
220-
output_string os ">";
219+
output_string os ">"
221220

222221
and goutput_gactual env os ty = goutput_typ env os ty
223222

@@ -864,14 +863,14 @@ let goutput_superclass env os = function
864863
| Some typ -> output_string os "extends "; (goutput_typ_with_shortened_class_syntax env) os typ
865864

866865
let goutput_superinterfaces env os imp =
867-
if imp = [] then () else
868-
output_string os "implements ";
869-
output_seq "," (goutput_typ_with_shortened_class_syntax env) os imp
866+
if not (List.isEmpty imp) then
867+
output_string os "implements "
868+
output_seq "," (goutput_typ_with_shortened_class_syntax env) os imp
870869

871870
let goutput_implements env os (imp:ILTypes) =
872-
if imp.Length = 0 then () else
873-
output_string os "implements ";
874-
output_seq "," (goutput_typ_with_shortened_class_syntax env) os imp
871+
if not (List.isEmpty imp) then
872+
output_string os "implements "
873+
output_seq "," (goutput_typ_with_shortened_class_syntax env) os imp
875874

876875
let the = function Some x -> x | None -> failwith "the"
877876

src/absil/ilread.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ and seekReadTypeDefOrRef ctxt numtypars boxity (ginst:ILTypes) (TaggedIndex(tag,
18161816
| tag when tag = tdor_TypeDef -> seekReadTypeDefAsType ctxt boxity ginst idx
18171817
| tag when tag = tdor_TypeRef -> seekReadTypeRefAsType ctxt boxity ginst idx
18181818
| tag when tag = tdor_TypeSpec ->
1819-
if ginst.Length > 0 then dprintn ("type spec used as type constructor for a generic instantiation: ignoring instantiation")
1819+
if not (List.isEmpty ginst) then dprintn ("type spec used as type constructor for a generic instantiation: ignoring instantiation")
18201820
readBlobHeapAsType ctxt numtypars (seekReadTypeSpecRow ctxt idx)
18211821
| _ -> failwith "seekReadTypeDefOrRef ctxt"
18221822

src/absil/ilwrite.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,10 +1307,10 @@ and GetMethodDefOrRefAsUncodedToken (tag, idx) =
13071307
getUncodedToken tab idx
13081308

13091309
and GetMethodSpecInfoAsUncodedToken cenv env ((_, _, _, _, _, _, minst:ILGenericArgs) as minfo) =
1310-
if minst.Length > 0 then
1311-
getUncodedToken TableNames.MethodSpec (GetMethodSpecInfoAsMethodSpecIdx cenv env minfo)
1312-
else
1313-
GetMethodDefOrRefAsUncodedToken (GetMethodRefInfoAsMethodRefOrDef false cenv env (GetMethodRefInfoOfMethodSpecInfo minfo))
1310+
if List.isEmpty minst then
1311+
GetMethodDefOrRefAsUncodedToken (GetMethodRefInfoAsMethodRefOrDef false cenv env (GetMethodRefInfoOfMethodSpecInfo minfo))
1312+
else
1313+
getUncodedToken TableNames.MethodSpec (GetMethodSpecInfoAsMethodSpecIdx cenv env minfo)
13141314

13151315
and GetMethodSpecAsUncodedToken cenv env mspec =
13161316
GetMethodSpecInfoAsUncodedToken cenv env (InfoOfMethodSpec mspec)
@@ -2475,7 +2475,7 @@ let GenReturnPass3 cenv (returnv: ILReturn) =
24752475
let GetMethodDefSigAsBytes cenv env (mdef: ILMethodDef) =
24762476
emitBytesViaBuffer (fun bb ->
24772477
bb.EmitByte (callconvToByte mdef.GenericParams.Length mdef.CallingConv)
2478-
if mdef.GenericParams.Length > 0 then bb.EmitZ32 mdef.GenericParams.Length
2478+
if not (List.isEmpty mdef.GenericParams) then bb.EmitZ32 mdef.GenericParams.Length
24792479
bb.EmitZ32 mdef.Parameters.Length
24802480
EmitType cenv env bb mdef.Return.Type
24812481
mdef.ParameterTypes |> List.iter (EmitType cenv env bb))

src/fsharp/CompileOps.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4287,7 +4287,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
42874287
// specified in the attributes
42884288
|> List.distinctBy (fun s -> try Path.GetFileNameWithoutExtension(s) with _ -> s)
42894289

4290-
if designTimeAssemblyNames.Length > 0 then
4290+
if not (List.isEmpty designTimeAssemblyNames) then
42914291

42924292
// Find the SystemRuntimeAssemblyVersion value to report in the TypeProviderConfig.
42934293
let primaryAssemblyVersion =

src/fsharp/IlxGen.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5188,7 +5188,7 @@ and GenMethodForBinding
51885188

51895189
let permissionSets = CreatePermissionSets cenv.g cenv.amap eenv securityAttributes
51905190

5191-
let secDecls = if securityAttributes.Length > 0 then (mkILSecurityDecls permissionSets) else (emptyILSecurityDecls)
5191+
let secDecls = if List.isEmpty securityAttributes then emptyILSecurityDecls else mkILSecurityDecls permissionSets
51925192

51935193
// Do not push the attributes to the method for events and properties
51945194
let ilAttrsCompilerGenerated = if v.IsCompilerGenerated then [ cenv.g.CompilerGeneratedAttribute ] else []
@@ -5207,7 +5207,7 @@ and GenMethodForBinding
52075207
// Does the function have an explicit [<EntryPoint>] attribute?
52085208
let isExplicitEntryPoint = HasFSharpAttribute cenv.g cenv.g.attrib_EntryPointAttribute attrs
52095209

5210-
let mdef = mdef.WithSecurity(securityAttributes.Length > 0).WithPInvoke(hasDllImport)
5210+
let mdef = mdef.WithSecurity(not (List.isEmpty securityAttributes)).WithPInvoke(hasDllImport)
52115211
let mdef = mdef.WithPreserveSig(hasPreserveSigImplFlag || hasPreserveSigNamedArg).WithSynchronized(hasSynchronizedImplFlag).WithNoInlining(hasNoInliningFlag).WithAggressiveInlining(hasAggressiveInliningImplFlag)
52125212
let mdef =
52135213
{ mdef with
@@ -6238,7 +6238,7 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon:Tycon) =
62386238
not (HasFSharpAttribute cenv.g cenv.g.attrib_DebuggerTypeProxyAttribute tycon.Attribs))
62396239

62406240
let permissionSets = CreatePermissionSets cenv.g cenv.amap eenv securityAttrs
6241-
let secDecls = if securityAttrs.Length > 0 then (mkILSecurityDecls permissionSets) else (emptyILSecurityDecls)
6241+
let secDecls = if List.isEmpty securityAttrs then emptyILSecurityDecls else mkILSecurityDecls permissionSets
62426242

62436243
let ilDebugDisplayAttributes =
62446244
[ yield! GenAttrs cenv eenv debugDisplayAttrs
@@ -6699,7 +6699,7 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon:Tycon) =
66996699

67006700
| _ -> failwith "??"
67016701

6702-
let tdef = tdef.WithHasSecurity(securityAttrs.Length > 0)
6702+
let tdef = tdef.WithHasSecurity(not (List.isEmpty securityAttrs))
67036703
let tdef =
67046704
{ tdef with
67056705
SecurityDecls = secDecls }

src/fsharp/LexFilter.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ type TokenTup =
444444
let (|TyparsCloseOp|_|) (txt:string) =
445445
let angles = txt |> Seq.takeWhile (fun c -> c = '>') |> Seq.toList
446446
let afterAngles = txt |> Seq.skipWhile (fun c -> c = '>') |> Seq.toList
447-
if angles.Length = 0 then None else
447+
if List.isEmpty angles then None else
448448

449449
let afterOp =
450450
match (new System.String(Array.ofSeq afterAngles)) with

src/fsharp/MethodOverrides.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ let GetAbstractMethInfosForSynMethodDecl(infoReader:InfoReader,ad,memberName:Ide
709709
GetIntrinsicMethInfosOfType infoReader (Some(memberName.idText), ad, AllowMultiIntfInstantiations.Yes) IgnoreOverrides bindm ty
710710
let dispatchSlots = minfos |> List.filter (fun minfo -> minfo.IsDispatchSlot)
711711
let topValSynArities = SynInfo.AritiesOfArgs valSynData
712-
let topValSynArities = if topValSynArities.Length > 0 then topValSynArities.Tail else topValSynArities
712+
let topValSynArities = if List.isEmpty topValSynArities then topValSynArities else topValSynArities.Tail
713713
let dispatchSlotsArityMatch = dispatchSlots |> List.filter (fun minfo -> minfo.NumArgs = topValSynArities)
714714
dispatchSlots,dispatchSlotsArityMatch
715715

src/fsharp/NameResolution.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ let AddValRefToNameEnv nenv (vref:ValRef) =
568568

569569
/// Add a set of active pattern result tags to the environment.
570570
let AddActivePatternResultTagsToNameEnv (apinfo: PrettyNaming.ActivePatternInfo) nenv ty m =
571-
if apinfo.Names.Length = 0 then nenv else
571+
if List.isEmpty apinfo.Names then nenv else
572572
let apresl = List.indexed apinfo.Names
573573
{ nenv with
574574
eUnqualifiedItems =
@@ -675,13 +675,13 @@ let private AddPartsOfTyconRefToNameEnv bulkAddMode ownDefinition (g:TcGlobals)
675675
| _ -> Item.UnqualifiedType [tcref]))
676676
else
677677
tab
678-
if isILOrRequiredQualifiedAccess || ucrefs.Length = 0 then
678+
if isILOrRequiredQualifiedAccess || List.isEmpty ucrefs then
679679
tab
680680
else
681681
AddUnionCases2 bulkAddMode tab ucrefs
682682

683683
let ePatItems =
684-
if isILOrRequiredQualifiedAccess || ucrefs.Length = 0 then
684+
if isILOrRequiredQualifiedAccess || List.isEmpty ucrefs then
685685
nenv.ePatItems
686686
else
687687
AddUnionCases1 nenv.ePatItems ucrefs
@@ -1718,14 +1718,14 @@ let CheckForTypeLegitimacyAndMultipleGenericTypeAmbiguities
17181718
// no explicit type instantiation
17191719
typeNameResInfo.StaticArgsInfo.HasNoStaticArgsInfo &&
17201720
// some type arguments required on all types (note sorted by typar count above)
1721-
tcref.Typars(m).Length > 0 &&
1721+
not (List.isEmpty (tcref.Typars m)) &&
17221722
// plausible types have different arities
17231723
(tcrefs |> Seq.distinctBy (fun (_,tcref) -> tcref.Typars(m).Length) |> Seq.length > 1) ->
17241724
[ for (resInfo,tcref) in tcrefs do
17251725
let resInfo = resInfo.AddWarning (fun _typarChecker -> errorR(Error(FSComp.SR.nrTypeInstantiationNeededToDisambiguateTypesWithSameName(tcref.DisplayName, tcref.DisplayNameWithStaticParametersAndUnderscoreTypars),m)))
17261726
yield (resInfo,tcref) ]
17271727

1728-
| [(resInfo,tcref)] when typeNameResInfo.StaticArgsInfo.HasNoStaticArgsInfo && tcref.Typars(m).Length > 0 && typeNameResInfo.ResolutionFlag = ResolveTypeNamesToTypeRefs ->
1728+
| [(resInfo,tcref)] when typeNameResInfo.StaticArgsInfo.HasNoStaticArgsInfo && not (List.isEmpty (tcref.Typars m)) && typeNameResInfo.ResolutionFlag = ResolveTypeNamesToTypeRefs ->
17291729
let resInfo =
17301730
resInfo.AddWarning (fun (ResultTyparChecker typarChecker) ->
17311731
if not (typarChecker()) then
@@ -3235,9 +3235,9 @@ let NeedsWorkAfterResolution namedItem =
32353235
| Item.CtorGroup(_,minfos) -> minfos.Length > 1 || minfos |> List.exists (fun minfo -> not (isNil minfo.FormalMethodInst))
32363236
| Item.Property(_,pinfos) -> pinfos.Length > 1
32373237
| Item.ImplicitOp(_, { contents = Some(TraitConstraintSln.FSMethSln(_, vref, _)) })
3238-
| Item.Value vref | Item.CustomBuilder (_,vref) -> vref.Typars.Length > 0
3238+
| Item.Value vref | Item.CustomBuilder (_,vref) -> not (List.isEmpty vref.Typars)
32393239
| Item.CustomOperation (_,_,Some minfo) -> not (isNil minfo.FormalMethodInst)
3240-
| Item.ActivePatternCase apref -> apref.ActivePatternVal.Typars.Length > 0
3240+
| Item.ActivePatternCase apref -> not (List.isEmpty apref.ActivePatternVal.Typars)
32413241
| _ -> false
32423242

32433243
/// Specifies additional work to do after an item has been processed further in type checking.

src/fsharp/Optimizer.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2507,7 +2507,7 @@ and TryInlineApplication cenv env finfo (tyargs: TType list, args: Expr list, m)
25072507
false
25082508
else true)))) ->
25092509

2510-
let isBaseCall = args.Length > 0 &&
2510+
let isBaseCall = not (List.isEmpty args) &&
25112511
match args.[0] with
25122512
| Expr.Val(vref, _, _) when vref.BaseOrThisInfo = BaseVal -> true
25132513
| _ -> false

src/fsharp/TypeChecker.fs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,7 +2812,7 @@ let TcVal checkAttributes cenv env tpenv (vref:ValRef) optInst optAfterResolutio
28122812
// If we have got an explicit instantiation then use that
28132813
| Some(vrefFlags, checkTys) ->
28142814
let checkInst (tinst:TypeInst) =
2815-
if not v.IsMember && not v.PermitsExplicitTypeInstantiation && tinst.Length > 0 && v.Typars.Length > 0 then
2815+
if not v.IsMember && not v.PermitsExplicitTypeInstantiation && not (List.isEmpty tinst) && not (List.isEmpty v.Typars) then
28162816
warning(Error(FSComp.SR.tcDoesNotAllowExplicitTypeArguments(v.DisplayName), m))
28172817
match vrec with
28182818
| ValInRecScope false ->
@@ -7495,13 +7495,13 @@ and TcComputationExpression cenv env overallTy mWhole interpExpr builderTy tpenv
74957495
| StripApps(SingleIdent nm, [StripApps(SingleIdent nm2, args); arg2]) when
74967496
PrettyNaming.IsInfixOperator nm.idText &&
74977497
expectedArgCountForCustomOperator nm2 > 0 &&
7498-
args.Length > 0 ->
7498+
not (List.isEmpty args) ->
74997499
let estimatedRangeOfIntendedLeftAndRightArguments = unionRanges (List.last args).Range arg2.Range
75007500
errorR(Error(FSComp.SR.tcUnrecognizedQueryBinaryOperator(), estimatedRangeOfIntendedLeftAndRightArguments))
75017501
true
75027502
| SynExpr.Tuple( (StripApps(SingleIdent nm2, args) :: _), _, m) when
75037503
expectedArgCountForCustomOperator nm2 > 0 &&
7504-
args.Length > 0 ->
7504+
not (List.isEmpty args) ->
75057505
let estimatedRangeOfIntendedLeftAndRightArguments = unionRanges (List.last args).Range m.EndRange
75067506
errorR(Error(FSComp.SR.tcUnrecognizedQueryBinaryOperator(), estimatedRangeOfIntendedLeftAndRightArguments))
75077507
true
@@ -11254,7 +11254,7 @@ and AnalyzeAndMakeAndPublishRecursiveValue overridesOK isGeneratedEventVal cenv
1125411254
let prelimTyscheme = TypeScheme(enclosingDeclaredTypars@declaredTypars, ty)
1125511255
let partialValReprInfo = TranslateTopValSynInfo mBinding (TcAttributes cenv envinner) valSynInfo
1125611256
let topValInfo = UseSyntacticArity declKind prelimTyscheme partialValReprInfo
11257-
let hasDeclaredTypars = declaredTypars.Length > 0
11257+
let hasDeclaredTypars = not (List.isEmpty declaredTypars)
1125811258
let prelimValScheme = ValScheme(bindingId, prelimTyscheme, topValInfo, memberInfoOpt, false, inlineFlag, NormalVal, vis, false, false, false, hasDeclaredTypars)
1125911259

1126011260
// Check the literal r.h.s., if any
@@ -13576,14 +13576,14 @@ module MutRecBindingChecking =
1357613576
let ad = env.eAccessRights
1357713577
let mvvs = ForceRaise (ResolveLongIndentAsModuleOrNamespace cenv.tcSink ResultCollectionSettings.AllResults cenv.amap m OpenQualified env.eNameResEnv ad p false)
1357813578
let modrefs = mvvs |> List.map p23
13579-
if modrefs.Length > 0 && modrefs |> List.forall (fun modref -> modref.IsNamespace) then
13579+
if not (List.isEmpty modrefs) && modrefs |> List.forall (fun modref -> modref.IsNamespace) then
1358013580
errorR(Error(FSComp.SR.tcModuleAbbreviationForNamespace(fullDisplayTextOfModRef (List.head modrefs)), m))
1358113581
let modrefs = modrefs |> List.filter (fun mvv -> not mvv.IsNamespace)
13582+
if List.isEmpty modrefs then env else
1358213583
modrefs |> List.iter (fun modref -> CheckEntityAttributes cenv.g modref m |> CommitOperationResult)
13583-
let env = (if modrefs.Length > 0 then AddModuleAbbreviationAndReport cenv.tcSink scopem id modrefs env else env)
13584+
let env = AddModuleAbbreviationAndReport cenv.tcSink scopem id modrefs env
1358413585
env
1358513586

13586-
1358713587
/// Update the contents accessible via the recursive namespace declaration, if any
1358813588
let TcMutRecDefns_UpdateNSContents mutRecNSInfo =
1358913589
match mutRecNSInfo with
@@ -15130,10 +15130,10 @@ module EstablishTypeDefinitionCores =
1513015130
if allowed then
1513115131
if kind = explicitKind then
1513215132
warning(PossibleUnverifiableCode(m))
15133-
elif thisTyconRef.Typars(m).Length > 0 then
15134-
errorR (Error(FSComp.SR.tcGenericTypesCannotHaveStructLayout(), m))
15135-
else
15133+
elif List.isEmpty (thisTyconRef.Typars m) then
1513615134
errorR (Error(FSComp.SR.tcOnlyStructsCanHaveStructLayout(), m))
15135+
else
15136+
errorR (Error(FSComp.SR.tcGenericTypesCannotHaveStructLayout(), m))
1513715137
| None -> ()
1513815138

1513915139
let hiddenReprChecks(hasRepr) =
@@ -16363,14 +16363,13 @@ let rec TcSignatureElementNonMutRec cenv parent typeNames endm (env: TcEnv) synS
1636316363

1636416364
let modrefs = unfilteredModrefs |> List.filter (fun modref -> not modref.IsNamespace)
1636516365

16366-
if unfilteredModrefs.Length > 0 && List.isEmpty modrefs then
16366+
if not (List.isEmpty unfilteredModrefs) && List.isEmpty modrefs then
1636716367
errorR(Error(FSComp.SR.tcModuleAbbreviationForNamespace(fullDisplayTextOfModRef (List.head unfilteredModrefs)), m))
1636816368

16369+
if List.isEmpty modrefs then return env else
1636916370
modrefs |> List.iter (fun modref -> CheckEntityAttributes cenv.g modref m |> CommitOperationResult)
1637016371

16371-
let env =
16372-
if modrefs.Length > 0 then AddModuleAbbreviationAndReport cenv.tcSink scopem id modrefs env
16373-
else env
16372+
let env = AddModuleAbbreviationAndReport cenv.tcSink scopem id modrefs env
1637416373
return env
1637516374

1637616375
| SynModuleSigDecl.HashDirective _ ->

0 commit comments

Comments
 (0)