Skip to content

Commit

Permalink
Left fold ImmutableDict(args::Pair...) (#35871)
Browse files Browse the repository at this point in the history
Currently, the behavior of `Dict(pairs...)` and
`Base.ImmutableDict(pairs...)` are different:

    julia> Dict(:a => 1, :a => 2)[:a]
    2

    julia> Base.ImmutableDict(:a => 1, :a => 2)[:a]
    1

This PR fixes the latter to return 2.
  • Loading branch information
tkf authored May 15, 2020
1 parent cb2e8c8 commit fe59346
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ Create a new entry in the `ImmutableDict` for a `key => value` pair
ImmutableDict
ImmutableDict(KV::Pair{K,V}) where {K,V} = ImmutableDict{K,V}(KV[1], KV[2])
ImmutableDict(t::ImmutableDict{K,V}, KV::Pair) where {K,V} = ImmutableDict{K,V}(t, KV[1], KV[2])
ImmutableDict(KV::Pair, rest::Pair...) = ImmutableDict(ImmutableDict(rest...), KV)
ImmutableDict(KV::Pair, rest::Pair...) = ImmutableDict(ImmutableDict(KV), rest...)

function in(key_value::Pair, dict::ImmutableDict, valcmp=(==))
key, value = key_value
Expand Down
3 changes: 2 additions & 1 deletion test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,8 @@ import Base.ImmutableDict
v = [k1 => v1, k2 => v2]
d5 = ImmutableDict(v...)
@test d5 == d2
@test collect(d5) == v
@test reverse(collect(d5)) == v
@test ImmutableDict(:a => 1, :a => 2)[:a] == 2

@test !haskey(ImmutableDict(-0.0=>1), 0.0)
end
Expand Down

2 comments on commit fe59346

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.