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

Commit6f2cb0d

Browse files
forkiKevinRansom
authored andcommitted
We only need to check for mangledGenericTypeNameSym once (dotnet#5633)
* We only need to check for mangledGenericTypeNameSym once* ShortCut name checking* Reduce number of LastIndexOf calls* Reduce number of LastIndexOf calls* Reduce number of LastIndexOf calls* Incorporate feedback* Use PrettyNaming.DemangleGenericTypeName instead of ungenericizeTypeName* Remove couple of double checks* Update illib.fs
1 parent7f7ef16 commit6f2cb0d

File tree

8 files changed

+62
-82
lines changed

8 files changed

+62
-82
lines changed

‎src/absil/il.fs‎

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,11 @@ let unsplitTypeName (ns, n) =
154154
|[]-> String.concat"." ns+"."+ n
155155
|_-> n
156156

157-
letsplitTypeNameRightAux nm=
158-
if String.contains nm'.'then
159-
letidx= String.rindex nm'.'
160-
lets1,s2= splitNameAt nm idx
161-
Some s1, s2
162-
else None, nm
157+
letsplitTypeNameRightAux(nm:string)=
158+
letidx= nm.LastIndexOf'.'
159+
if idx=-1then None, nmelse
160+
lets1,s2= splitNameAt nm idx
161+
Some s1, s2
163162

164163
letsplitTypeNameRight nm=
165164
memoizeNamespaceRightTable.GetOrAdd(nm, splitTypeNameRightAux)
@@ -4189,23 +4188,6 @@ let resolveILMethodRef td mref = resolveILMethodRefWithRescope id td mref
41894188
letmkRefToILModule m=
41904189
ILModuleRef.Create(m.Name,true, None)
41914190

4192-
4193-
letungenericizeTypeName n=
4194-
letsym='`'
4195-
if
4196-
String.contains n sym&&
4197-
(* check what comes after the symbol is a number*)
4198-
(letm= String.rindex n sym
4199-
letres= ref(m< n.Length-1)
4200-
for i= m+1to n.Length-1do
4201-
res:=!res&& n.[i]>='0'&& n.[i]<='9'
4202-
!res)
4203-
then
4204-
letpos= String.rindex n sym
4205-
String.sub n0 pos
4206-
else n
4207-
4208-
42094191
typeILEventRef=
42104192
{ erA:ILTypeRef; erB:string}
42114193
static memberCreate(a,b)={erA=a;erB=b}

‎src/absil/il.fsi‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,9 +1540,6 @@ val typeNameForGlobalFunctions: string
15401540

15411541
val isTypeNameForGlobalFunctions: string-> bool
15421542

1543-
val ungenericizeTypeName: string-> string(* e.g. List`1--> List*)
1544-
1545-
15461543
//====================================================================
15471544
// PART 2
15481545
//

‎src/absil/illib.fs‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -452,23 +452,13 @@ type String with
452452
member inlinex.EndsWithOrdinal(value)=
453453
x.EndsWith(value, StringComparison.Ordinal)
454454

455-
moduleString=
456-
letindexNotFound()= raise(new KeyNotFoundException("An index for the character was not found in the string"))
457-
455+
moduleString=
458456
letmake(n:int)(c:char):string=new String(c, n)
459457

460458
letget(str:string)i= str.[i]
461459

462460
letsub(s:string)(start:int)(len:int)= s.Substring(start,len)
463461

464-
letindex(s:string)(c:char)=
465-
letr= s.IndexOf(c)
466-
if r=-1then indexNotFound()else r
467-
468-
letrindex(s:string)(c:char)=
469-
letr= s.LastIndexOf(c)
470-
if r=-1then indexNotFound()else r
471-
472462
letcontains(s:string)(c:char)= s.IndexOf(c)<>-1
473463

474464
letorder= LanguagePrimitives.FastGenericComparer<string>

‎src/fsharp/CompileOps.fs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,13 +2609,13 @@ type TcConfigBuilder =
26092609
membertcConfigB.RemoveReferencedAssemblyByPath(m,path)=
26102610
tcConfigB.referencedDLLs<- tcConfigB.referencedDLLs|> List.filter(fun ar-> ar.Range<> m|| ar.Text<> path)
26112611

2612-
static memberSplitCommandLineResourceInfori=
2613-
if String.contains ri','then
2614-
letp= String.index ri','
2612+
static memberSplitCommandLineResourceInfo(ri:string)=
2613+
letp= ri.IndexOf','
2614+
if p<>-1then
26152615
letfile= String.sub ri0 p
26162616
letrest= String.sub ri(p+1)(String.length ri- p-1)
2617-
if String.containsrest','then
2618-
letp= String.index rest','
2617+
letp=rest.IndexOf','
2618+
if p<>-1then
26192619
letname= String.sub rest0 p+".resources"
26202620
letpubpri= String.sub rest(p+1)(rest.Length- p-1)
26212621
if pubpri="public"then file, name, ILResourceAccess.Public

‎src/fsharp/NameResolution.fs‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -985,10 +985,8 @@ type TypeNameResolutionStaticArgsInfo =
985985

986986
// Get the first possible mangled name of the type, assuming the args are generic args
987987
memberx.MangledNameForType nm=
988-
if IsMangledGenericName nm|| x.NumStaticArgs=0then nm
989-
else nm+"`"+string x.NumStaticArgs
990-
991-
988+
if x.NumStaticArgs=0|| TryDemangleGenericNameAndPos nm<> ValueNonethen nm
989+
else nm+"`"+ string x.NumStaticArgs
992990

993991
[<NoEquality; NoComparison>]
994992
/// Represents information which guides name resolution of types.
@@ -1018,7 +1016,11 @@ let LookupTypeNameInEntityHaveArity nm (staticResInfo: TypeNameResolutionStaticA
10181016
/// Unqualified lookups of type names where the number of generic arguments is known
10191017
/// from context, e.g. List<arg>. Rebindings due to 'open' may have rebound identifiers.
10201018
letLookupTypeNameInEnvHaveArity fq nm numTyArgs(nenv:NameResolutionEnv)=
1021-
letkey=if IsMangledGenericName nmthen DecodeGenericTypeName nmelse NameArityPair(nm,numTyArgs)
1019+
letkey=
1020+
match TryDemangleGenericNameAndPos nmwith
1021+
| ValueSome pos-> DecodeGenericTypeName pos nm
1022+
|_-> NameArityPair(nm,numTyArgs)
1023+
10221024
match nenv.TyconsByDemangledNameAndArity(fq).TryFind(key)with
10231025
| Some res-> Some res
10241026
| None-> nenv.TyconsByAccessNames(fq).TryFind nm|> Option.map List.head
@@ -1041,15 +1043,17 @@ let LookupTypeNameInEnvHaveArity fq nm numTyArgs (nenv:NameResolutionEnv) =
10411043
// also be used to qualify access if needed, though this is almost never needed.
10421044

10431045
letLookupTypeNameNoArity nm(byDemangledNameAndArity:LayeredMap<NameArityPair,_>)(byAccessNames:LayeredMultiMap<string,_>)=
1044-
if IsMangledGenericName nmthen
1045-
match byDemangledNameAndArity.TryFind(DecodeGenericTypeName nm)with
1046-
| Some res->[res]
1047-
| None->
1048-
match byAccessNames.TryFind nmwith
1049-
| Some res-> res
1050-
| None->[]
1051-
else
1052-
byAccessNames.[nm]
1046+
match TryDemangleGenericNameAndPos nmwith
1047+
| ValueSome pos->
1048+
letdemangled= DecodeGenericTypeName pos nm
1049+
match byDemangledNameAndArity.TryFind demangledwith
1050+
| Some res->[res]
1051+
| None->
1052+
match byAccessNames.TryFind nmwith
1053+
| Some res-> res
1054+
| None->[]
1055+
|_->
1056+
byAccessNames.[nm]
10531057

10541058
/// Qualified lookup of type names in the environment
10551059
letLookupTypeNameInEnvNoArity fq nm(nenv:NameResolutionEnv)=

‎src/fsharp/NicePrint.fs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ module private PrintIL =
102102
openMicrosoft.FSharp.Compiler.AbstractIL.IL
103103

104104
letfullySplitILTypeRef(tref:ILTypeRef)=
105-
(List.collect IL.splitNamespace(tref.Enclosing@[IL.ungenericizeTypeName tref.Name]))
105+
(List.collect IL.splitNamespace(tref.Enclosing@[PrettyNaming.DemangleGenericTypeName tref.Name]))
106106

107107
letlayoutILTypeRefName denv path=
108108
letpath=
@@ -193,7 +193,7 @@ module private PrintIL =
193193
letargs= signatur.ArgTypes|> List.map(layoutILType denv ilTyparSubst)
194194
letres=
195195
match conswith
196-
| Some className-> layoutILTypeRefName denv(SplitNamesForILPath(ungenericizeTypeName className))^^(pruneParms className ilTyparSubst|> paramsL)// special case for constructor return-type (viz., the class itself)
196+
| Some className-> layoutILTypeRefName denv(SplitNamesForILPath(PrettyNaming.DemangleGenericTypeName className))^^(pruneParms className ilTyparSubst|> paramsL)// special case for constructor return-type (viz., the class itself)
197197
| None-> signatur.ReturnType|> layoutILType denv ilTyparSubst
198198
match argswith
199199
|[]-> WordL.structUnit^^ WordL.arrow^^ res
@@ -226,7 +226,7 @@ module private PrintIL =
226226
// return type be passed along as the `cons` parameter.)
227227
letres=
228228
match conswith
229-
| Some className-> layoutILTypeRefName denv(SplitNamesForILPath(ungenericizeTypeName className))^^(pruneParms className ilTyparSubst|> paramsL)// special case for constructor return-type (viz., the class itself)
229+
| Some className-> layoutILTypeRefName denv(SplitNamesForILPath(PrettyNaming.DemangleGenericTypeName className))^^(pruneParms className ilTyparSubst|> paramsL)// special case for constructor return-type (viz., the class itself)
230230
| None-> retType|> layoutILType denv ilTyparSubst
231231
match parameterswith
232232
|[]-> WordL.structUnit^^ WordL.arrow^^ res

‎src/fsharp/PrettyNaming.fs‎

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -484,30 +484,36 @@ module public Microsoft.FSharp.Compiler.PrettyNaming
484484

485485
let [<Literal>]privatemangledGenericTypeNameSym='`'
486486

487-
letIsMangledGenericName(n:string)=
488-
n.IndexOf mangledGenericTypeNameSym<>-1&&
487+
letTryDemangleGenericNameAndPos(n:string)=
489488
(* check what comes after the symbol is a number*)
490-
letm= n.LastIndexOf mangledGenericTypeNameSym
491-
let mutableres= m< n.Length-1
492-
for i= m+1to n.Length-1do
493-
res<- res&& n.[i]>='0'&& n.[i]<='9'
494-
res
489+
letpos= n.LastIndexOf mangledGenericTypeNameSym
490+
if pos=-1then ValueNoneelse
491+
let mutableres= pos< n.Length-1
492+
let mutablei= pos+1
493+
while res&& i< n.Lengthdo
494+
letchar= n.[i]
495+
ifnot(char>='0'&& char<='9')then
496+
res<-false
497+
i<- i+1
498+
if resthen
499+
ValueSome pos
500+
else
501+
ValueNone
495502

496503
typeNameArityPair= NameArityPairofstring*int
497504

498-
letDecodeGenericTypeName n=
499-
if IsMangledGenericName nthen
500-
letpos= n.LastIndexOf mangledGenericTypeNameSym
501-
letres= n.Substring(0,pos)
502-
letnum= n.Substring(pos+1,n.Length- pos-1)
503-
NameArityPair(res, int32 num)
504-
else NameArityPair(n,0)
505-
506-
letDemangleGenericTypeName n=
507-
if IsMangledGenericName nthen
508-
letpos= n.LastIndexOf mangledGenericTypeNameSym
509-
n.Substring(0,pos)
510-
else n
505+
letDecodeGenericTypeName pos(mangledName:string)=
506+
letres= mangledName.Substring(0,pos)
507+
letnum= mangledName.Substring(pos+1,mangledName.Length- pos-1)
508+
NameArityPair(res, int32 num)
509+
510+
letDemangleGenericTypeNameWithPos pos(mangledName:string)=
511+
mangledName.Substring(0,pos)
512+
513+
letDemangleGenericTypeName(mangledName:string)=
514+
match TryDemangleGenericNameAndPos mangledNamewith
515+
| ValueSome pos-> DemangleGenericTypeNameWithPos pos mangledName
516+
|_-> mangledName
511517

512518
letprivatechopStringTo(s:string)(c:char)=
513519
match s.IndexOf cwith

‎src/fsharp/tast.fs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,11 @@ let KeyTyconByDemangledNameAndArity nm (typars: _ list) x =
480480

481481
/// Generic types can be accessed either by 'List' or 'List`1'. This lists both keys. The second form should really be deprecated.
482482
letKeyTyconByAccessNames nm x=
483-
if IsMangledGenericName nmthen
484-
letdnm= DemangleGenericTypeName nm
483+
match TryDemangleGenericNameAndPos nmwith
484+
| ValueSome pos->
485+
letdnm= DemangleGenericTypeNameWithPos pos nm
485486
[| KeyValuePair(nm,x); KeyValuePair(dnm,x)|]
486-
else
487+
|_->
487488
[| KeyValuePair(nm,x)|]
488489

489490
typeModuleOrNamespaceKind=

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp