Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbbf07fb

Browse files
forkidsyme
authored andcommitted
List.isEmpty instead of iterating through the list to get the count (dotnet#4439)
1 parente4fb0fc commitbbf07fb

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
andgoutput_gactuals env os inst=
216-
if inst.Length=0then()
217-
else
218-
output_string os"<";
216+
ifnot(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
andgoutput_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
letgoutput_superinterfaces env os imp=
867-
ifimp=[]then()else
868-
output_string os"implements";
869-
output_seq","(goutput_typ_with_shortened_class_syntax env) os imp
866+
ifnot(List.isEmpty imp)then
867+
output_string os"implements"
868+
output_seq","(goutput_typ_with_shortened_class_syntax env) os imp
870869

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

876875
letthe=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
| tagwhen tag= tdor_TypeDef-> seekReadTypeDefAsType ctxt boxity ginst idx
18171817
| tagwhen tag= tdor_TypeRef-> seekReadTypeRefAsType ctxt boxity ginst idx
18181818
| tagwhen tag= tdor_TypeSpec->
1819-
ifginst.Length>0then dprintn("type spec used as type constructor for a generic instantiation: ignoring instantiation")
1819+
ifnot(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
andGetMethodSpecInfoAsUncodedToken cenv env((_,_,_,_,_,_,minst:ILGenericArgs)as minfo)=
1310-
ifminst.Length>0then
1311-
getUncodedToken TableNames.MethodSpec(GetMethodSpecInfoAsMethodSpecIdxcenv env minfo)
1312-
else
1313-
GetMethodDefOrRefAsUncodedToken(GetMethodRefInfoAsMethodRefOrDeffalsecenv env(GetMethodRefInfoOfMethodSpecInfominfo))
1310+
ifList.isEmpty minstthen
1311+
GetMethodDefOrRefAsUncodedToken(GetMethodRefInfoAsMethodRefOrDeffalsecenv env(GetMethodRefInfoOfMethodSpecInfominfo))
1312+
else
1313+
getUncodedToken TableNames.MethodSpec(GetMethodSpecInfoAsMethodSpecIdxcenv env minfo)
13141314

13151315
andGetMethodSpecAsUncodedToken cenv env mspec=
13161316
GetMethodSpecInfoAsUncodedToken cenv env(InfoOfMethodSpec mspec)
@@ -2475,7 +2475,7 @@ let GenReturnPass3 cenv (returnv: ILReturn) =
24752475
letGetMethodDefSigAsBytes cenv env(mdef:ILMethodDef)=
24762476
emitBytesViaBuffer(fun bb->
24772477
bb.EmitByte(callconvToByte mdef.GenericParams.Length mdef.CallingConv)
2478-
if mdef.GenericParams.Length>0then bb.EmitZ32 mdef.GenericParams.Length
2478+
ifnot(List.isEmptymdef.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-
ifdesignTimeAssemblyNames.Length>0then
4290+
ifnot(List.isEmpty designTimeAssemblyNames)then
42914291

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

‎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
letpermissionSets= CreatePermissionSets cenv.g cenv.amap eenv securityAttributes
51905190

5191-
letsecDecls=ifsecurityAttributes.Length>0then(mkILSecurityDecls permissionSets)else(emptyILSecurityDecls)
5191+
letsecDecls=ifList.isEmpty securityAttributesthenemptyILSecurityDeclselsemkILSecurityDecls permissionSets
51925192

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

5210-
letmdef= mdef.WithSecurity(securityAttributes.Length>0).WithPInvoke(hasDllImport)
5210+
letmdef= mdef.WithSecurity(not(List.isEmpty securityAttributes)).WithPInvoke(hasDllImport)
52115211
letmdef= mdef.WithPreserveSig(hasPreserveSigImplFlag|| hasPreserveSigNamedArg).WithSynchronized(hasSynchronizedImplFlag).WithNoInlining(hasNoInliningFlag).WithAggressiveInlining(hasAggressiveInliningImplFlag)
52125212
letmdef=
52135213
{ mdefwith
@@ -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
letpermissionSets= CreatePermissionSets cenv.g cenv.amap eenv securityAttrs
6241-
letsecDecls=ifsecurityAttrs.Length>0then(mkILSecurityDecls permissionSets)else(emptyILSecurityDecls)
6241+
letsecDecls=ifList.isEmpty securityAttrsthenemptyILSecurityDeclselsemkILSecurityDecls permissionSets
62426242

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

67006700
|_-> failwith"??"
67016701

6702-
lettdef= tdef.WithHasSecurity(securityAttrs.Length>0)
6702+
lettdef= tdef.WithHasSecurity(not(List.isEmpty securityAttrs))
67036703
lettdef=
67046704
{ tdefwith
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
letangles= txt|> Seq.takeWhile(fun c-> c='>')|> Seq.toList
446446
letafterAngles= txt|> Seq.skipWhile(fun c-> c='>')|> Seq.toList
447-
ifangles.Length=0then Noneelse
447+
ifList.isEmpty anglesthen Noneelse
448448

449449
letafterOp=
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
letdispatchSlots= minfos|> List.filter(fun minfo-> minfo.IsDispatchSlot)
711711
lettopValSynArities= SynInfo.AritiesOfArgs valSynData
712-
lettopValSynArities=iftopValSynArities.Length>0then topValSynArities.Tailelse topValSynArities
712+
lettopValSynArities=ifList.isEmpty topValSynAritiesthen topValSynAritieselse topValSynArities.Tail
713713
letdispatchSlotsArityMatch= 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
letAddActivePatternResultTagsToNameEnv(apinfo:PrettyNaming.ActivePatternInfo)nenv ty m=
571-
if apinfo.Names.Length=0then nenvelse
571+
ifList.isEmptyapinfo.Namesthen nenvelse
572572
letapresl= List.indexed apinfo.Names
573573
{ nenvwith
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=0then
678+
if isILOrRequiredQualifiedAccess||List.isEmpty ucrefsthen
679679
tab
680680
else
681681
AddUnionCases2 bulkAddMode tab ucrefs
682682

683683
letePatItems=
684-
if isILOrRequiredQualifiedAccess||ucrefs.Length=0then
684+
if isILOrRequiredQualifiedAccess||List.isEmpty ucrefsthen
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 tcrefsdo
17251725
letresInfo= 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
letresInfo=
17301730
resInfo.AddWarning(fun(ResultTyparCheckertyparChecker)->
17311731
ifnot(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.isEmptyvref.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.isEmptyapref.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
elsetrue))))->
25092509

2510-
letisBaseCall= args.Length>0&&
2510+
letisBaseCall=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.isEmptyv.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-
ifmodrefs.Length > 0 && modrefs |> List.forall (fun modref -> modref.IsNamespace) then
13579+
ifnot (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 thenAddModuleAbbreviationAndReport 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-
ifunfilteredModrefs.Length > 0 && List.isEmpty modrefs then
16366+
ifnot (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)

[8]ページ先頭

©2009-2025 Movatter.jp