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

Commit3667caa

Browse files
smoothdeveloperKevinRansom
authored andcommitted
Deprecate dictionary.of list (dotnet#2301)
* replace all calls to Dictionary.ofList with procedural dictionary creation / population* fixing missing initial size parameter when instanciating the dictionaries in* MethodCalls.convertProvidedExpressionToExprAndWitness* TcGlobals.betterTyconRefMap* AbstractIL.Morphs.code_instr2instrs* Fix lacking explicit HashIdentity.Structural parameter, wrapped in Dictionary.newWithSizemissing type annotation
1 parent4b23b22 commit3667caa

File tree

7 files changed

+115
-91
lines changed

7 files changed

+115
-91
lines changed

‎src/absil/il.fs‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,11 +2494,19 @@ let prependInstrsToCode (instrs: ILInstr list) (c2: ILCode) =
24942494
letn= instrs.Length
24952495
match c2.Instrs.[0]with
24962496
// If there is a sequence point as the first instruction then keep it at the front
2497-
| I_seqpoint_as i0->
2498-
{ c2with Labels= Dictionary.ofList[for kvpin c2.Labels->(kvp.Key,if kvp.Value=0then0else kvp.Value+ n)]
2499-
Instrs= Array.append[| i0|](Array.append instrs c2.Instrs.[1..])}
2500-
|_->
2501-
{ c2with Labels= Dictionary.ofList[for kvpin c2.Labels->(kvp.Key, kvp.Value+ n)]
2497+
| I_seqpoint_as i0->
2498+
letlabels=
2499+
letdict= Dictionary.newWithSize c2.Labels.Count
2500+
for kvpin c2.Labelsdo dict.Add(kvp.Key,if kvp.Value=0then0else kvp.Value+ n)
2501+
dict
2502+
{ c2with Labels= labels
2503+
Instrs= Array.concat[|[|i0|]; instrs; c2.Instrs.[1..]|]}
2504+
|_->
2505+
letlabels=
2506+
letdict= Dictionary.newWithSize c2.Labels.Count
2507+
for kvpin c2.Labelsdo dict.Add(kvp.Key, kvp.Value+ n)
2508+
dict
2509+
{ c2with Labels= labels
25022510
Instrs= Array.append instrs c2.Instrs}
25032511

25042512
letprependInstrsToMethod new_code md=

‎src/absil/ilbinary.fs‎

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -758,36 +758,40 @@ let isNoArgInstr i =
758758
|_->false
759759

760760
letILCmpInstrMap=
761-
lazy
762-
(Dictionary.ofList
763-
[ BI_beq, i_beq
764-
BI_bgt, i_bgt
765-
BI_bgt_un, i_bgt_un
766-
BI_bge, i_bge
767-
BI_bge_un, i_bge_un
768-
BI_ble, i_ble
769-
BI_ble_un, i_ble_un
770-
BI_blt, i_blt
771-
BI_blt_un, i_blt_un
772-
BI_bne_un, i_bne_un
773-
BI_brfalse, i_brfalse
774-
BI_brtrue, i_brtrue])
761+
lazy(
762+
letdict= Dictionary.newWithSize12
763+
dict.Add(BI_beq, i_beq)
764+
dict.Add(BI_bgt, i_bgt)
765+
dict.Add(BI_bgt_un, i_bgt_un)
766+
dict.Add(BI_bge, i_bge)
767+
dict.Add(BI_bge_un, i_bge_un)
768+
dict.Add(BI_ble, i_ble)
769+
dict.Add(BI_ble_un, i_ble_un)
770+
dict.Add(BI_blt, i_blt)
771+
dict.Add(BI_blt_un, i_blt_un)
772+
dict.Add(BI_bne_un, i_bne_un)
773+
dict.Add(BI_brfalse, i_brfalse)
774+
dict.Add(BI_brtrue, i_brtrue)
775+
dict
776+
)
775777

776778
letILCmpInstrRevMap=
777-
lazy
778-
(Dictionary.ofList
779-
[ BI_beq, i_beq_s
780-
BI_bgt, i_bgt_s
781-
BI_bgt_un, i_bgt_un_s
782-
BI_bge, i_bge_s
783-
BI_bge_un, i_bge_un_s
784-
BI_ble, i_ble_s
785-
BI_ble_un, i_ble_un_s
786-
BI_blt, i_blt_s
787-
BI_blt_un, i_blt_un_s
788-
BI_bne_un, i_bne_un_s
789-
BI_brfalse, i_brfalse_s
790-
BI_brtrue, i_brtrue_s])
779+
lazy(
780+
letdict= Dictionary.newWithSize12
781+
dict.Add( BI_beq, i_beq_s)
782+
dict.Add( BI_bgt, i_bgt_s)
783+
dict.Add( BI_bgt_un, i_bgt_un_s)
784+
dict.Add( BI_bge, i_bge_s)
785+
dict.Add( BI_bge_un, i_bge_un_s)
786+
dict.Add( BI_ble, i_ble_s)
787+
dict.Add( BI_ble_un, i_ble_un_s)
788+
dict.Add( BI_blt, i_blt_s)
789+
dict.Add( BI_blt_un, i_blt_un_s)
790+
dict.Add( BI_bne_un, i_bne_un_s)
791+
dict.Add( BI_brfalse, i_brfalse_s)
792+
dict.Add( BI_brtrue, i_brtrue_s)
793+
dict
794+
)
791795

792796
// From corhdr.h
793797

‎src/absil/illib.fs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,9 @@ module String =
442442

443443
moduleDictionary=
444444

445-
let inlineofList l=
446-
letdict=new System.Collections.Generic.Dictionary<_,_>(List.length l, HashIdentity.Structural)
447-
l|> List.iter(fun(k,v)-> dict.Add(k,v))
448-
dict
445+
let inlinenewWithSize(size:int)= System.Collections.Generic.Dictionary<_,_>(size, HashIdentity.Structural)
449446

447+
450448
moduleLazy=
451449
letforce(x:Lazy<'T>)= x.Force()
452450

‎src/absil/ilmorph.fs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ let code_instr2instrs f (code: ILCode) =
3333
codebuf.Add instr2
3434
nw<- nw+1
3535
old<- old+1
36-
adjust.[old]<- nw
36+
adjust.[old]<- nw
37+
letlabels=
38+
letdict= Dictionary.newWithSize code.Labels.Count
39+
for kvpin code.Labelsdo dict.Add(kvp.Key, adjust.[kvp.Value])
40+
dict
3741
{ codewith
3842
Instrs= codebuf.ToArray()
39-
Labels=Dictionary.ofList[for kvpin code.Labels-> kvp.Key, adjust.[kvp.Value]]}
43+
Labels=labels}
4044

4145

4246

‎src/fsharp/IlxGen.fs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,10 +1457,15 @@ type CodeGenBuffer(m:range,
14571457
instrs|> Array.mapi(fun idx i2->if idx=0then ielseif i=== i2then AI_nopelse i2)
14581458
|_->
14591459
instrs
1460+
1461+
letcodeLabels=
1462+
letdict= Dictionary.newWithSize(codeLabelToPC.Count+ codeLabelToCodeLabel.Count)
1463+
for kvpin codeLabelToPCdo dict.Add(kvp.Key, lab2pc0 kvp.Key)
1464+
for kvpin codeLabelToCodeLabeldo dict.Add(kvp.Key, lab2pc0 kvp.Key)
1465+
dict
14601466
ResizeArray.toList locals,
14611467
maxStack,
1462-
(Dictionary.ofList[for kvpin codeLabelToPC->(kvp.Key, lab2pc0 kvp.Key)
1463-
for kvpin codeLabelToCodeLabel->(kvp.Key, lab2pc0 kvp.Key)]),
1468+
codeLabels,
14641469
instrs,
14651470
ResizeArray.toList exnSpecs,
14661471
Option.isSome seqpoint

‎src/fsharp/MethodCalls.fs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -916,11 +916,13 @@ module ProvidedMethodCalls =
916916
paramVars:Tainted<ProvidedVar>[],
917917
g,amap,mut,isProp,isSuperInit,m,
918918
expr:Tainted<ProvidedExpr>)=
919-
letvarConv=
920-
[for(v,e)in Seq.zip(paramVars|> Seq.map(fun x-> x.PUntaint(id,m)))(Option.toList thisArg@ allArgs)do
921-
yield(v,(None,e))]
922-
|> Dictionary.ofList
923-
919+
letvarConv=
920+
// note: using paramVars.Length as assumed initial size, but this might not
921+
// be the optimal value; this wasn't checked before obsoleting Dictionary.ofList
922+
letdict= Dictionary.newWithSize paramVars.Length
923+
for v,ein Seq.zip(paramVars|> Seq.map(fun x-> x.PUntaint(id,m)))(Option.toList thisArg@ allArgs)do
924+
dict.Add(v,(None,e))
925+
dict
924926
let recexprToExprAndWitness top(ea:Tainted<ProvidedExpr>)=
925927
letfail()= error(Error(FSComp.SR.etUnsupportedProvidedExpression(ea.PUntaint((fun etree-> etree.UnderlyingExpressionString), m)),m))
926928
match eawith

‎src/fsharp/TcGlobals.fs‎

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -683,47 +683,47 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
683683
letbetterTyconRefMap=
684684
begin
685685
letentries1=
686-
["Int32", v_int_tcr
687-
"IntPtr", v_nativeint_tcr
688-
"UIntPtr", v_unativeint_tcr
689-
"Int16", v_int16_tcr
690-
"Int64", v_int64_tcr
691-
"UInt16", v_uint16_tcr
692-
"UInt32", v_uint32_tcr
693-
"UInt64", v_uint64_tcr
694-
"SByte", v_sbyte_tcr
695-
"Decimal", v_decimal_tcr
696-
"Byte", v_byte_tcr
697-
"Boolean", v_bool_tcr
698-
"String", v_string_tcr
699-
"Object", v_obj_tcr
700-
"Exception", v_exn_tcr
701-
"Char", v_char_tcr
702-
"Double", v_float_tcr
703-
"Single", v_float32_tcr]
704-
|>List.map(fun(nm,tcr)->
686+
[|"Int32", v_int_tcr
687+
"IntPtr", v_nativeint_tcr
688+
"UIntPtr", v_unativeint_tcr
689+
"Int16", v_int16_tcr
690+
"Int64", v_int64_tcr
691+
"UInt16", v_uint16_tcr
692+
"UInt32", v_uint32_tcr
693+
"UInt64", v_uint64_tcr
694+
"SByte", v_sbyte_tcr
695+
"Decimal", v_decimal_tcr
696+
"Byte", v_byte_tcr
697+
"Boolean", v_bool_tcr
698+
"String", v_string_tcr
699+
"Object", v_obj_tcr
700+
"Exception", v_exn_tcr
701+
"Char", v_char_tcr
702+
"Double", v_float_tcr
703+
"Single", v_float32_tcr|]
704+
|>Array.map(fun(nm,tcr)->
705705
letty= mkNonGenericTy tcr
706706
nm, findSysTyconRef sys nm,(fun _-> ty))
707707

708708
letentries2=
709-
["FSharpFunc`2", v_fastFunc_tcr,(fun tinst-> mkFunTy(List.item0 tinst)(List.item1 tinst))
710-
"Tuple`2",v_ref_tuple2_tcr, decodeTupleTy tupInfoRef
711-
"Tuple`3",v_ref_tuple3_tcr, decodeTupleTy tupInfoRef
712-
"Tuple`4",v_ref_tuple4_tcr, decodeTupleTy tupInfoRef
713-
"Tuple`5",v_ref_tuple5_tcr, decodeTupleTy tupInfoRef
714-
"Tuple`6",v_ref_tuple6_tcr, decodeTupleTy tupInfoRef
715-
"Tuple`7",v_ref_tuple7_tcr, decodeTupleTy tupInfoRef
716-
"Tuple`8",v_ref_tuple8_tcr, decodeTupleTy tupInfoRef
717-
"ValueTuple`2",v_struct_tuple2_tcr, decodeTupleTytupInfoStruct
718-
"ValueTuple`3",v_struct_tuple3_tcr, decodeTupleTy tupInfoStruct
719-
"ValueTuple`4",v_struct_tuple4_tcr, decodeTupleTy tupInfoStruct
720-
"ValueTuple`5",v_struct_tuple5_tcr, decodeTupleTy tupInfoStruct
721-
"ValueTuple`6",v_struct_tuple6_tcr, decodeTupleTy tupInfoStruct
722-
"ValueTuple`7",v_struct_tuple7_tcr, decodeTupleTy tupInfoStruct
723-
"ValueTuple`8",v_struct_tuple8_tcr, decodeTupleTy tupInfoStruct]
724-
725-
letentries=(entries1@ entries2)
726-
709+
[|
710+
"FSharpFunc`2",v_fastFunc_tcr,(fun tinst-> mkFunTy(List.item0 tinst)(List.item1 tinst))
711+
"Tuple`2",v_ref_tuple2_tcr, decodeTupleTy tupInfoRef
712+
"Tuple`3",v_ref_tuple3_tcr, decodeTupleTy tupInfoRef
713+
"Tuple`4",v_ref_tuple4_tcr, decodeTupleTy tupInfoRef
714+
"Tuple`5",v_ref_tuple5_tcr, decodeTupleTy tupInfoRef
715+
"Tuple`6",v_ref_tuple6_tcr, decodeTupleTy tupInfoRef
716+
"Tuple`7",v_ref_tuple7_tcr, decodeTupleTy tupInfoRef
717+
"Tuple`8",v_ref_tuple8_tcr, decodeTupleTytupInfoRef
718+
"ValueTuple`2",v_struct_tuple2_tcr, decodeTupleTy tupInfoStruct
719+
"ValueTuple`3",v_struct_tuple3_tcr, decodeTupleTy tupInfoStruct
720+
"ValueTuple`4",v_struct_tuple4_tcr, decodeTupleTy tupInfoStruct
721+
"ValueTuple`5",v_struct_tuple5_tcr, decodeTupleTy tupInfoStruct
722+
"ValueTuple`6",v_struct_tuple6_tcr, decodeTupleTy tupInfoStruct
723+
"ValueTuple`7",v_struct_tuple7_tcr, decodeTupleTy tupInfoStruct
724+
"ValueTuple`8", v_struct_tuple8_tcr, decodeTupleTy tupInfoStruct|]
725+
726+
letentries= Array.append entries1 entries2
727727
if compilingFslibthen
728728
// This map is for use when building FSharp.Core.dll. The backing Tycon's may not yet exist for
729729
// the TyconRef's we have in our hands, hence we can't dereference them to find their stamps.
@@ -732,10 +732,12 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
732732
//
733733
// Make it lazy to avoid dereferencing while setting up the base imports.
734734
letdict=
735-
lazy
736-
entries
737-
|> List.map(fun(nm,tcref,builder)-> nm,(fun tcref2 tinst->if tyconRefEq tcref tcref2then Some(builder tinst)else None))
738-
|> Dictionary.ofList
735+
lazy(
736+
letdict= Dictionary.newWithSize entries.Length
737+
for nm, tcref, builderin entriesdo
738+
dict.Add(nm,fun tcref2 tinst->if tyconRefEq tcref tcref2then Some(builder tinst)else None)
739+
dict
740+
)
739741
(fun(tcref: EntityRef)tinst->
740742
letdict= dict.Value
741743
letkey= tcref.LogicalName
@@ -750,10 +752,11 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
750752
// Make it lazy to avoid dereferencing while setting up the base imports.
751753
letdict=
752754
lazy
753-
entries
754-
|> List.filter(fun(_,tcref,_)-> tcref.CanDeref)
755-
|> List.map(fun(_,tcref,builder)-> tcref.Stamp, builder)
756-
|> Dictionary.ofList
755+
letdict= Dictionary.newWithSize entries.Length
756+
for_, tcref, builderin entriesdo
757+
if tcref.CanDerefthen
758+
dict.Add(tcref.Stamp, builder)
759+
dict
757760
(fun tcref2 tinst->
758761
letdict= dict.Value
759762
letkey= tcref2.Stamp

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp