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

Commit2f8ccbc

Browse files
smoothdeveloperKevinRansom
authored andcommitted
replace list.Length = 0 with isNil (dotnet#2294)
* This is tiny optimization and code cleaning around empty list checks* inline function AbstractIL.IL.isNil used to call to List.isEmpty, replace it with property access list.Length* harmonize empty list comparison `list.Length = 0` across the code (only in places which had AbstractIL.IL open already) to always use isNil* Update illib.fsfix back isNil, this PR still fix consistency over `list.Length = 0` which is lot less efficient than `List.isEmpty`
1 parent0a38f47 commit2f8ccbc

File tree

13 files changed

+14
-14
lines changed

13 files changed

+14
-14
lines changed

‎src/absil/il.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2714,7 +2714,7 @@ let mkILTypeDefForGlobalFunctions ilg (methods,fields) = mkILSimpleClass ilg (ty
27142714
letdestTypeDefsWithGlobalFunctionsFirst ilg(tdefs:ILTypeDefs)=
27152715
letl= tdefs.AsList
27162716
lettop,nontop= l|> List.partition(fun td-> td.Name= typeNameForGlobalFunctions)
2717-
lettop2=iftop.Length=0then[ mkILTypeDefForGlobalFunctions ilg(emptyILMethods, emptyILFields)]else top
2717+
lettop2=ifisNil topthen[ mkILTypeDefForGlobalFunctions ilg(emptyILMethods, emptyILFields)]else top
27182718
top2@nontop
27192719

27202720
letmkILSimpleModule assname modname dll subsystemVersion useHighEntropyVA tdefs hashalg locale flags exportedTypes metadataVersion=

‎src/absil/illib.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let (>>>&) (x:int32) (n:int32) = int32 (uint32 x >>> n)
2222

2323
letnotlazy v= Lazy<_>.CreateFromValue v
2424

25-
let inlineisNilx= List.isEmptyx
25+
let inlineisNill= List.isEmptyl
2626
let inlineisNonNull x=not(isNull x)
2727
let inlinenonNull msg x=if isNull xthen failwith("null:"^ msg)else x
2828
let(===) x y= LanguagePrimitives.PhysicalEquality x y

‎src/absil/ilreflect.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ let convMethodSpec cenv emEnv (mspec:ILMethodSpec) =
760760
lettypT= convType cenv emEnv mspec.EnclosingType(* (instanced) parent Type*)
761761
letmethInfo= convMethodRef cenv emEnv typT mspec.MethodRef(* (generic) method of (generic) parent*)
762762
letmethInfo=
763-
if mspec.GenericArgs.Length=0then
763+
ifisNilmspec.GenericArgsthen
764764
methInfo// non generic
765765
else
766766
letminstTs= convTypesToArray cenv emEnv mspec.GenericArgs
@@ -1404,7 +1404,7 @@ let rec buildMethodPass2 cenv tref (typB:TypeBuilder) emEnv (mdef : ILMethodDef)
14041404
letimplflags= convMethodImplFlags mdef
14051405
letcconv= convCallConv mdef.CallingConv
14061406
letmref= mkRefToILMethod(tref,mdef)
1407-
letemEnv=if mdef.IsEntryPoint&& mdef.ParameterTypes.Length=0then
1407+
letemEnv=if mdef.IsEntryPoint&&isNilmdef.ParameterTypesthen
14081408
(* Bug 2209:
14091409
Here, we collect the entry points generated by ilxgen corresponding to the top-level effects.
14101410
Users can (now) annotate their own functions with EntryPoint attributes.

‎src/absil/ilsupp.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ let linkNativeResources (unlinkedResources:byte[] list) (ulLinkedResourceBaseRV
584584
let mutableobjBytes:byte[]=[||]
585585

586586
letunlinkedResources= unlinkedResources|> List.filter(fun arr-> arr.Length>0)
587-
ifunlinkedResources.Length=0then// bail if there's nothing to link
587+
ifisNil unlinkedResourcesthen// bail if there's nothing to link
588588
objBytes
589589
else
590590
// Part 1: Write unlinked resources to an object file for linking

‎src/absil/ilwrite.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ and GetModuleRefAsFileIdx cenv mref =
738738

739739
letisScopeRefLocal scoref=(scoref= ILScopeRef.Local)
740740
letisTypeRefLocal(tref:ILTypeRef)= isScopeRefLocal tref.Scope
741-
letisTypeLocal(typ:ILType)= typ.IsNominal&& typ.GenericArgs.Length=0&& isTypeRefLocal typ.TypeRef
741+
letisTypeLocal(typ:ILType)= typ.IsNominal&&isNiltyp.GenericArgs&& isTypeRefLocal typ.TypeRef
742742

743743
// --------------------------------------------------------------------
744744
// Scopes to Implementation elements.

‎src/absil/ilwritepdb.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ let generatePortablePdb fixupSPs (embedAllSource:bool) (embedSourceList:string l
294294
letdocumentIndex=
295295
letincludeSource file=
296296
letisInList=
297-
ifembedSourceList.Length=0thenfalse
297+
ifisNil embedSourceListthenfalse
298298
else
299299
embedSourceList|> List.tryFind(fun f-> String.Compare(file, f, StringComparison.OrdinalIgnoreCase)=0)|> Option.isSome
300300

‎src/fsharp/IlxGen.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4657,7 +4657,7 @@ and GenBindAfterSequencePoint cenv cgbuf eenv sp (TBind(vspec,rhsExpr,_)) =
46574657
GenExpr cenv cgbuf eenv SPSuppress rhsExpr discard
46584658

46594659
// The initialization code for static 'let' and 'do' bindings gets compiled into the initialization .cctor for the whole file
4660-
|_when vspec.IsClassConstructor&& vspec.TopValActualParent.TyparsNoRange.Length=0->
4660+
|_when vspec.IsClassConstructor&&isNilvspec.TopValActualParent.TyparsNoRange->
46614661
lettps,_,_,_,cctorBody,_= IteratedAdjustArityOfLambda cenv.g cenv.amap vspec.ValReprInfo.Value rhsExpr
46624662
leteenv= EnvForTypars tps eenv
46634663
GenExpr cenv cgbuf eenv SPSuppress cctorBody discard

‎src/fsharp/NameResolution.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ let NextExtensionMethodPriority() = uint64 (newStamp())
392392
letprivateGetCSharpStyleIndexedExtensionMembersForTyconRef(amap:Import.ImportMap)m(tcrefOfStaticClass:TyconRef)=
393393
letg= amap.g
394394
// Type must be non-generic and have 'Extension' attribute
395-
if tcrefOfStaticClass.Typars(m).Length=0&& TyconRefHasAttribute g m g.attrib_ExtensionAttribute tcrefOfStaticClassthen
395+
ifisNil(tcrefOfStaticClass.Typars(m))&& TyconRefHasAttribute g m g.attrib_ExtensionAttribute tcrefOfStaticClassthen
396396
letpri= NextExtensionMethodPriority()
397397
lettyp= generalizedTyconRef tcrefOfStaticClass
398398

‎src/fsharp/NicePrint.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ module InfoMemberPrinting =
12561256
letparamDatas= minfo.GetParamDatas(amap, m, minst)
12571257
letlayout=
12581258
layout^^
1259-
if(List.concat paramDatas).Length=0then
1259+
ifisNil(List.concat paramDatas)then
12601260
WordL.structUnit
12611261
else
12621262
sepListL WordL.arrow(List.map((List.map(layoutParamData denv))>> sepListL WordL.star) paramDatas)

‎src/fsharp/PostInferenceChecks.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ let CheckEntityDefn cenv env (tycon:Entity) =
15301530
setterArgs.Length<> getterArgs.Length)
15311531
||
15321532
(letnargs= pinfo.GetParamTypes(cenv.amap,m).Length
1533-
others|> List.exists(fun pinfo2->(pinfo2.GetParamTypes(cenv.amap,m).Length=0)<>(nargs=0))))then
1533+
others|> List.exists(fun pinfo2->(isNil(pinfo2.GetParamTypes(cenv.amap,m)))<>(nargs=0))))then
15341534

15351535
errorR(Error(FSComp.SR.chkPropertySameNameIndexer(nm),m))
15361536

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp