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

Commitf1558b7

Browse files
authored
Add new implementation of IEnumerable<_> for dict (dotnet#5918)
1 parent98c5bf1 commitf1558b7

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

‎src/FSharp.Profiles.props‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</PropertyGroup>
1111

1212
<PropertyGroupCondition="'$(TargetFramework)' == 'netstandard1.6' or '$(TargetFramework)' == 'netcoreapp1.0'">
13+
<DefineConstants>$(DefineConstants);NETSTANDARD</DefineConstants>
1314
<DefineConstants>$(DefineConstants);NETSTANDARD1_6</DefineConstants>
1415
<DefineConstants>$(DefineConstants);FX_NO_APP_DOMAINS</DefineConstants>
1516
<DefineConstants>$(DefineConstants);FX_NO_ARRAY_LONG_LENGTH</DefineConstants>

‎src/FSharpSource.Profiles.targets‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<!-- These should be distinguished in the future-->
1414

1515
<PropertyGroupCondition="'$(TargetDotnetProfile)'=='coreclr'">
16+
<DefineConstants>$(DefineConstants);NETSTANDARD</DefineConstants>
1617
<DefineConstants>$(DefineConstants);NETSTANDARD1_6</DefineConstants>
1718
<DefineConstants>$(DefineConstants);FX_NO_APP_DOMAINS</DefineConstants>
1819
<DefineConstants>$(DefineConstants);FX_NO_ARRAY_LONG_LENGTH</DefineConstants>

‎src/fsharp/FSharp.Core/fslib-extra-pervasives.fs‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ module ExtraTopLevelOperators =
4343
[<DebuggerDisplay("Count = {Count}")>]
4444
[<DebuggerTypeProxy(typedefof<DictDebugView<_,_,_>>)>]
4545
typeDictImpl<'SafeKey,'Key,'T>(t:Dictionary<'SafeKey,'T>,makeSafeKey: 'Key->'SafeKey,getKey: 'SafeKey->'Key)=
46-
46+
#if NETSTANDARD
47+
static letemptyEnumerator=(Array.empty<KeyValuePair<'Key, 'T>>:> seq<_>).GetEnumerator()
48+
#endif
4749
memberx.Count= t.Count
4850

4951
// Give a read-only view of the dictionary
@@ -110,8 +112,34 @@ module ExtraTopLevelOperators =
110112
members.GetEnumerator()=
111113
// We use an array comprehension here instead of seq {} as otherwise we get incorrect
112114
// IEnumerator.Reset() and IEnumerator.Current semantics.
115+
// Coreclr has a bug with SZGenericEnumerators --- implement a correct enumerator. On desktop use the desktop implementation because it's ngened.
116+
#if!NETSTANDARD
113117
letkvps=[|for(KeyValue(k,v))in t-> KeyValuePair(getKey k, v)|]:> seq<_>
114118
kvps.GetEnumerator()
119+
#else
120+
letendIndex= t.Count
121+
if endIndex=0then emptyEnumerator
122+
else
123+
letkvps=[|for(KeyValue(k,v))in t-> KeyValuePair(getKey k, v)|]
124+
let mutableindex=-1
125+
letcurrent()=
126+
if index<0then raise<| InvalidOperationException(SR.GetString(SR.enumerationNotStarted))
127+
if index>= endIndexthen raise<| InvalidOperationException(SR.GetString(SR.enumerationAlreadyFinished))
128+
kvps.[index]
129+
130+
{new IEnumerator<_>with
131+
member__.Current= current()
132+
interface System.Collections.IEnumeratorwith
133+
member__.Current= box(current())
134+
member__.MoveNext()=
135+
if index< endIndexthen
136+
index<- index+1
137+
index< endIndex
138+
elsefalse
139+
member__.Reset()= index<--1
140+
interface System.IDisposablewith
141+
memberself.Dispose()=()}
142+
#endif
115143

116144
interface System.Collections.IEnumerablewith
117145
members.GetEnumerator()=

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp