Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/FSharp.Profiles.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard1.6' or '$(TargetFramework)' == 'netcoreapp1.0'">
<DefineConstants>$(DefineConstants);NETSTANDARD</DefineConstants>
<DefineConstants>$(DefineConstants);NETSTANDARD1_6</DefineConstants>
<DefineConstants>$(DefineConstants);FX_NO_APP_DOMAINS</DefineConstants>
<DefineConstants>$(DefineConstants);FX_NO_ARRAY_LONG_LENGTH</DefineConstants>
Expand Down
1 change: 1 addition & 0 deletions src/FSharpSource.Profiles.targets
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<!-- These should be distinguished in the future -->

<PropertyGroup Condition="'$(TargetDotnetProfile)'=='coreclr'">
<DefineConstants>$(DefineConstants);NETSTANDARD</DefineConstants>
<DefineConstants>$(DefineConstants);NETSTANDARD1_6</DefineConstants>
<DefineConstants>$(DefineConstants);FX_NO_APP_DOMAINS</DefineConstants>
<DefineConstants>$(DefineConstants);FX_NO_ARRAY_LONG_LENGTH</DefineConstants>
Expand Down
30 changes: 29 additions & 1 deletion src/fsharp/FSharp.Core/fslib-extra-pervasives.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ module ExtraTopLevelOperators =
[<DebuggerDisplay("Count = {Count}")>]
[<DebuggerTypeProxy(typedefof<DictDebugView<_,_,_>>)>]
type DictImpl<'SafeKey,'Key,'T>(t : Dictionary<'SafeKey,'T>, makeSafeKey : 'Key->'SafeKey, getKey : 'SafeKey->'Key) =

#if NETSTANDARD
static let emptyEnumerator = (Array.empty<KeyValuePair<'Key, 'T>> :> seq<_>).GetEnumerator()
#endif
member x.Count = t.Count

// Give a read-only view of the dictionary
Expand Down Expand Up @@ -110,8 +112,34 @@ module ExtraTopLevelOperators =
member s.GetEnumerator() =
// We use an array comprehension here instead of seq {} as otherwise we get incorrect
// IEnumerator.Reset() and IEnumerator.Current semantics.
// Coreclr has a bug with SZGenericEnumerators --- implement a correct enumerator. On desktop use the desktop implementation because it's ngened.
#if !NETSTANDARD
let kvps = [| for (KeyValue (k,v)) in t -> KeyValuePair (getKey k, v) |] :> seq<_>
kvps.GetEnumerator()
#else
let endIndex = t.Count
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer this be called count since that's how it's used, but this isn't a hill I'm going to die on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brettfo endindex is the name for that value in the original bcl source code. I too chuckled over the ridiculousness of the name.

if endIndex = 0 then emptyEnumerator
else
let kvps = [| for (KeyValue (k,v)) in t -> KeyValuePair (getKey k, v) |]
let mutable index = -1
let current () =
if index < 0 then raise <| InvalidOperationException(SR.GetString(SR.enumerationNotStarted))
if index >= endIndex then raise <| InvalidOperationException(SR.GetString(SR.enumerationAlreadyFinished))
kvps.[index]

{new IEnumerator<_> with
member __.Current = current ()
interface System.Collections.IEnumerator with
member __.Current = box(current())
member __.MoveNext() =
if index < endIndex then
index <- index + 1
index < endIndex
else false
member __.Reset() = index <- -1
interface System.IDisposable with
member self.Dispose() = () }
#endif

interface System.Collections.IEnumerable with
member s.GetEnumerator() =
Expand Down