Skip to content

Commit

Permalink
List.isEmpty instead of iterating through the list to get the count
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Mar 6, 2018
1 parent 0adb823 commit 9daf0f3
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/absil/ilprint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ and goutput_typ_with_shortened_class_syntax env os = function
| typ2 -> goutput_typ env os typ2

and goutput_gactuals env os inst =
if inst.Length = 0 then ()
if List.isEmpty inst then ()
else
output_string os "<";
output_seq ", " (goutput_gactual env) os inst
Expand Down Expand Up @@ -869,7 +869,7 @@ let goutput_superinterfaces env os imp =
output_seq "," (goutput_typ_with_shortened_class_syntax env) os imp

let goutput_implements env os (imp:ILTypes) =
if imp.Length = 0 then () else
if List.isEmpty imp then () else
output_string os "implements ";
output_seq "," (goutput_typ_with_shortened_class_syntax env) os imp

Expand Down
2 changes: 1 addition & 1 deletion src/absil/ilread.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ and seekReadTypeDefOrRef ctxt numtypars boxity (ginst:ILTypes) (TaggedIndex(tag,
| tag when tag = tdor_TypeDef -> seekReadTypeDefAsType ctxt boxity ginst idx
| tag when tag = tdor_TypeRef -> seekReadTypeRefAsType ctxt boxity ginst idx
| tag when tag = tdor_TypeSpec ->
if ginst.Length > 0 then dprintn ("type spec used as type constructor for a generic instantiation: ignoring instantiation")
if not (List.isEmpty ginst) then dprintn ("type spec used as type constructor for a generic instantiation: ignoring instantiation")
readBlobHeapAsType ctxt numtypars (seekReadTypeSpecRow ctxt idx)
| _ -> failwith "seekReadTypeDefOrRef ctxt"

Expand Down
10 changes: 5 additions & 5 deletions src/absil/ilwrite.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,10 +1307,10 @@ and GetMethodDefOrRefAsUncodedToken (tag, idx) =
getUncodedToken tab idx

and GetMethodSpecInfoAsUncodedToken cenv env ((_, _, _, _, _, _, minst:ILGenericArgs) as minfo) =
if minst.Length > 0 then
getUncodedToken TableNames.MethodSpec (GetMethodSpecInfoAsMethodSpecIdx cenv env minfo)
else
GetMethodDefOrRefAsUncodedToken (GetMethodRefInfoAsMethodRefOrDef false cenv env (GetMethodRefInfoOfMethodSpecInfo minfo))
if List.isEmpty minst then
GetMethodDefOrRefAsUncodedToken (GetMethodRefInfoAsMethodRefOrDef false cenv env (GetMethodRefInfoOfMethodSpecInfo minfo))
else
getUncodedToken TableNames.MethodSpec (GetMethodSpecInfoAsMethodSpecIdx cenv env minfo)

and GetMethodSpecAsUncodedToken cenv env mspec =
GetMethodSpecInfoAsUncodedToken cenv env (InfoOfMethodSpec mspec)
Expand Down Expand Up @@ -2475,7 +2475,7 @@ let GenReturnPass3 cenv (returnv: ILReturn) =
let GetMethodDefSigAsBytes cenv env (mdef: ILMethodDef) =
emitBytesViaBuffer (fun bb ->
bb.EmitByte (callconvToByte mdef.GenericParams.Length mdef.CallingConv)
if mdef.GenericParams.Length > 0 then bb.EmitZ32 mdef.GenericParams.Length
if not (List.isEmpty mdef.GenericParams) then bb.EmitZ32 mdef.GenericParams.Length
bb.EmitZ32 mdef.Parameters.Length
EmitType cenv env bb mdef.Return.Type
mdef.ParameterTypes |> List.iter (EmitType cenv env bb))
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/CompileOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4287,7 +4287,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
// specified in the attributes
|> List.distinctBy (fun s -> try Path.GetFileNameWithoutExtension(s) with _ -> s)

if designTimeAssemblyNames.Length > 0 then
if not (List.isEmpty designTimeAssemblyNames) then

// Find the SystemRuntimeAssemblyVersion value to report in the TypeProviderConfig.
let primaryAssemblyVersion =
Expand Down
8 changes: 4 additions & 4 deletions src/fsharp/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5188,7 +5188,7 @@ and GenMethodForBinding

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

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

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

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

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

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

| _ -> failwith "??"

let tdef = tdef.WithHasSecurity(securityAttrs.Length > 0)
let tdef = tdef.WithHasSecurity(not (List.isEmpty securityAttrs))
let tdef =
{ tdef with
SecurityDecls = secDecls }
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/LexFilter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ type TokenTup =
let (|TyparsCloseOp|_|) (txt:string) =
let angles = txt |> Seq.takeWhile (fun c -> c = '>') |> Seq.toList
let afterAngles = txt |> Seq.skipWhile (fun c -> c = '>') |> Seq.toList
if angles.Length = 0 then None else
if List.isEmpty angles then None else

let afterOp =
match (new System.String(Array.ofSeq afterAngles)) with
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/MethodOverrides.fs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ let GetAbstractMethInfosForSynMethodDecl(infoReader:InfoReader,ad,memberName:Ide
GetIntrinsicMethInfosOfType infoReader (Some(memberName.idText), ad, AllowMultiIntfInstantiations.Yes) IgnoreOverrides bindm ty
let dispatchSlots = minfos |> List.filter (fun minfo -> minfo.IsDispatchSlot)
let topValSynArities = SynInfo.AritiesOfArgs valSynData
let topValSynArities = if topValSynArities.Length > 0 then topValSynArities.Tail else topValSynArities
let topValSynArities = if List.isEmpty topValSynArities then topValSynArities else topValSynArities.Tail
let dispatchSlotsArityMatch = dispatchSlots |> List.filter (fun minfo -> minfo.NumArgs = topValSynArities)
dispatchSlots,dispatchSlotsArityMatch

Expand Down
14 changes: 7 additions & 7 deletions src/fsharp/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ let AddValRefToNameEnv nenv (vref:ValRef) =

/// Add a set of active pattern result tags to the environment.
let AddActivePatternResultTagsToNameEnv (apinfo: PrettyNaming.ActivePatternInfo) nenv ty m =
if apinfo.Names.Length = 0 then nenv else
if List.isEmpty apinfo.Names then nenv else
let apresl = List.indexed apinfo.Names
{ nenv with
eUnqualifiedItems =
Expand Down Expand Up @@ -675,13 +675,13 @@ let private AddPartsOfTyconRefToNameEnv bulkAddMode ownDefinition (g:TcGlobals)
| _ -> Item.UnqualifiedType [tcref]))
else
tab
if isILOrRequiredQualifiedAccess || ucrefs.Length = 0 then
if isILOrRequiredQualifiedAccess || List.isEmpty ucrefs then
tab
else
AddUnionCases2 bulkAddMode tab ucrefs

let ePatItems =
if isILOrRequiredQualifiedAccess || ucrefs.Length = 0 then
if isILOrRequiredQualifiedAccess || List.isEmpty ucrefs then
nenv.ePatItems
else
AddUnionCases1 nenv.ePatItems ucrefs
Expand Down Expand Up @@ -1725,14 +1725,14 @@ let CheckForTypeLegitimacyAndMultipleGenericTypeAmbiguities
// no explicit type instantiation
typeNameResInfo.StaticArgsInfo.HasNoStaticArgsInfo &&
// some type arguments required on all types (note sorted by typar count above)
tcref.Typars(m).Length > 0 &&
not (List.isEmpty (tcref.Typars m)) &&
// plausible types have different arities
(tcrefs |> Seq.distinctBy (fun (_,tcref) -> tcref.Typars(m).Length) |> Seq.length > 1) ->
[ for (resInfo,tcref) in tcrefs do
let resInfo = resInfo.AddWarning (fun _typarChecker -> errorR(Error(FSComp.SR.nrTypeInstantiationNeededToDisambiguateTypesWithSameName(tcref.DisplayName, tcref.DisplayNameWithStaticParametersAndUnderscoreTypars),m)))
yield (resInfo,tcref) ]

| [(resInfo,tcref)] when typeNameResInfo.StaticArgsInfo.HasNoStaticArgsInfo && tcref.Typars(m).Length > 0 && typeNameResInfo.ResolutionFlag = ResolveTypeNamesToTypeRefs ->
| [(resInfo,tcref)] when typeNameResInfo.StaticArgsInfo.HasNoStaticArgsInfo && not (List.isEmpty (tcref.Typars m)) && typeNameResInfo.ResolutionFlag = ResolveTypeNamesToTypeRefs ->
let resInfo =
resInfo.AddWarning (fun (ResultTyparChecker typarChecker) ->
if not (typarChecker()) then
Expand Down Expand Up @@ -3223,9 +3223,9 @@ let NeedsWorkAfterResolution namedItem =
| Item.CtorGroup(_,minfos) -> minfos.Length > 1 || minfos |> List.exists (fun minfo -> not (isNil minfo.FormalMethodInst))
| Item.Property(_,pinfos) -> pinfos.Length > 1
| Item.ImplicitOp(_, { contents = Some(TraitConstraintSln.FSMethSln(_, vref, _)) })
| Item.Value vref | Item.CustomBuilder (_,vref) -> vref.Typars.Length > 0
| Item.Value vref | Item.CustomBuilder (_,vref) -> not (List.isEmpty vref.Typars)
| Item.CustomOperation (_,_,Some minfo) -> not (isNil minfo.FormalMethodInst)
| Item.ActivePatternCase apref -> apref.ActivePatternVal.Typars.Length > 0
| Item.ActivePatternCase apref -> not (List.isEmpty apref.ActivePatternVal.Typars)
| _ -> false

/// Specifies additional work to do after an item has been processed further in type checking.
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/Optimizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2507,7 +2507,7 @@ and TryInlineApplication cenv env finfo (tyargs: TType list, args: Expr list, m)
false
else true)))) ->

let isBaseCall = args.Length > 0 &&
let isBaseCall = not (List.isEmpty args) &&
match args.[0] with
| Expr.Val(vref, _, _) when vref.BaseOrThisInfo = BaseVal -> true
| _ -> false
Expand Down
27 changes: 13 additions & 14 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2810,7 +2810,7 @@ let TcVal checkAttributes cenv env tpenv (vref:ValRef) optInst optAfterResolutio
// If we have got an explicit instantiation then use that
| Some(vrefFlags, checkTys) ->
let checkInst (tinst:TypeInst) =
if not v.IsMember && not v.PermitsExplicitTypeInstantiation && tinst.Length > 0 && v.Typars.Length > 0 then
if not v.IsMember && not v.PermitsExplicitTypeInstantiation && not (List.isEmpty tinst) && not (List.isEmpty v.Typars) then
warning(Error(FSComp.SR.tcDoesNotAllowExplicitTypeArguments(v.DisplayName), m))
match vrec with
| ValInRecScope false ->
Expand Down Expand Up @@ -7493,13 +7493,13 @@ and TcComputationExpression cenv env overallTy mWhole interpExpr builderTy tpenv
| StripApps(SingleIdent nm, [StripApps(SingleIdent nm2, args); arg2]) when
PrettyNaming.IsInfixOperator nm.idText &&
expectedArgCountForCustomOperator nm2 > 0 &&
args.Length > 0 ->
not (List.isEmpty args) ->
let estimatedRangeOfIntendedLeftAndRightArguments = unionRanges (List.last args).Range arg2.Range
errorR(Error(FSComp.SR.tcUnrecognizedQueryBinaryOperator(), estimatedRangeOfIntendedLeftAndRightArguments))
true
| SynExpr.Tuple( (StripApps(SingleIdent nm2, args) :: _), _, m) when
expectedArgCountForCustomOperator nm2 > 0 &&
args.Length > 0 ->
not (List.isEmpty args) ->
let estimatedRangeOfIntendedLeftAndRightArguments = unionRanges (List.last args).Range m.EndRange
errorR(Error(FSComp.SR.tcUnrecognizedQueryBinaryOperator(), estimatedRangeOfIntendedLeftAndRightArguments))
true
Expand Down Expand Up @@ -11252,7 +11252,7 @@ and AnalyzeAndMakeAndPublishRecursiveValue overridesOK isGeneratedEventVal cenv
let prelimTyscheme = TypeScheme(enclosingDeclaredTypars@declaredTypars, ty)
let partialValReprInfo = TranslateTopValSynInfo mBinding (TcAttributes cenv envinner) valSynInfo
let topValInfo = UseSyntacticArity declKind prelimTyscheme partialValReprInfo
let hasDeclaredTypars = declaredTypars.Length > 0
let hasDeclaredTypars = not (List.isEmpty declaredTypars)
let prelimValScheme = ValScheme(bindingId, prelimTyscheme, topValInfo, memberInfoOpt, false, inlineFlag, NormalVal, vis, false, false, false, hasDeclaredTypars)

// Check the literal r.h.s., if any
Expand Down Expand Up @@ -13574,14 +13574,14 @@ module MutRecBindingChecking =
let ad = env.eAccessRights
let mvvs = ForceRaise (ResolveLongIndentAsModuleOrNamespace cenv.tcSink ResultCollectionSettings.AllResults cenv.amap m OpenQualified env.eNameResEnv ad p false)
let modrefs = mvvs |> List.map p23
if modrefs.Length > 0 && modrefs |> List.forall (fun modref -> modref.IsNamespace) then
if not (List.isEmpty modrefs) && modrefs |> List.forall (fun modref -> modref.IsNamespace) then
errorR(Error(FSComp.SR.tcModuleAbbreviationForNamespace(fullDisplayTextOfModRef (List.head modrefs)), m))
let modrefs = modrefs |> List.filter (fun mvv -> not mvv.IsNamespace)
if List.isEmpty modrefs then env else
modrefs |> List.iter (fun modref -> CheckEntityAttributes cenv.g modref m |> CommitOperationResult)
let env = (if modrefs.Length > 0 then AddModuleAbbreviationAndReport cenv.tcSink scopem id modrefs env else env)
let env = AddModuleAbbreviationAndReport cenv.tcSink scopem id modrefs env
env


/// Update the contents accessible via the recursive namespace declaration, if any
let TcMutRecDefns_UpdateNSContents mutRecNSInfo =
match mutRecNSInfo with
Expand Down Expand Up @@ -15128,10 +15128,10 @@ module EstablishTypeDefinitionCores =
if allowed then
if kind = explicitKind then
warning(PossibleUnverifiableCode(m))
elif thisTyconRef.Typars(m).Length > 0 then
errorR (Error(FSComp.SR.tcGenericTypesCannotHaveStructLayout(), m))
else
elif List.isEmpty (thisTyconRef.Typars m) then
errorR (Error(FSComp.SR.tcOnlyStructsCanHaveStructLayout(), m))
else
errorR (Error(FSComp.SR.tcGenericTypesCannotHaveStructLayout(), m))
| None -> ()

let hiddenReprChecks(hasRepr) =
Expand Down Expand Up @@ -16361,14 +16361,13 @@ let rec TcSignatureElementNonMutRec cenv parent typeNames endm (env: TcEnv) synS

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

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

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

let env =
if modrefs.Length > 0 then AddModuleAbbreviationAndReport cenv.tcSink scopem id modrefs env
else env
let env = AddModuleAbbreviationAndReport cenv.tcSink scopem id modrefs env
return env

| SynModuleSigDecl.HashDirective _ ->
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/fsc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1966,7 +1966,7 @@ let main2b (tcImportsCapture,dynamicAssemblyCreator) (Args (ctok, tcConfig: TcCo
// remove any security attributes from the top-level assembly attribute list
let topAttrs = {topAttrs with assemblyAttrs=topAssemblyAttrs}
let permissionSets = ilxGenerator.CreatePermissionSets securityAttrs
let secDecls = if securityAttrs.Length > 0 then mkILSecurityDecls permissionSets else emptyILSecurityDecls
let secDecls = if List.isEmpty securityAttrs then emptyILSecurityDecls else mkILSecurityDecls permissionSets

let ilxMainModule = MainModuleBuilder.CreateMainModule (ctok, tcConfig, tcGlobals, tcImports, pdbfile, assemblyName, outfile, topAttrs, idata, optDataResources, codegenResults, assemVerFromAttrib, metadataVersion, secDecls)

Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/fsi/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2029,7 +2029,7 @@ type internal FsiInteractionProcessor

// When the last declaration has a shape of DoExp (i.e., non-binding),
// transform it to a shape of "let it = <exp>", so we can refer it.
let defsA = if defsA.Length <= 1 || defsB.Length > 0 then defsA else
let defsA = if defsA.Length <= 1 || not (List.isEmpty defsB) then defsA else
match List.headAndTail (List.rev defsA) with
| SynModuleDecl.DoExpr(_,exp,_), rest -> (rest |> List.rev) @ (fsiDynamicCompiler.BuildItBinding exp)
| _ -> defsA
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/tast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ type Entity =
| [] -> nm
| tps ->
let nm = DemangleGenericTypeName nm
if withUnderscoreTypars && tps.Length > 0 then
if withUnderscoreTypars && not (List.isEmpty tps) then
nm + "<" + String.concat "," (Array.create tps.Length "_") + ">"
else
nm
Expand Down

0 comments on commit 9daf0f3

Please sign in to comment.