Skip to content

Commit

Permalink
Speed up map on tuples. Fix #15695 till #15516 fixes it properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
shashi committed Mar 30, 2016
1 parent 4a13500 commit 1a2da9e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ map(f, t::Tuple{}) = ()
map(f, t::Tuple{Any,}) = (f(t[1]),)
map(f, t::Tuple{Any, Any}) = (f(t[1]), f(t[2]))
map(f, t::Tuple{Any, Any, Any}) = (f(t[1]), f(t[2]), f(t[3]))
map(f, t::Tuple) = (f(t[1]), map(f,tail(t))...)
map(f, t::Tuple) = ([f(x) for x in t]...)
# 2 argument function
map(f, t::Tuple{}, s::Tuple{}) = ()
map(f, t::Tuple{Any,}, s::Tuple{Any,}) = (f(t[1],s[1]),)
Expand All @@ -81,7 +81,7 @@ heads(t::Tuple, ts::Tuple...) = (t[1], heads(ts...)...)
tails() = ()
tails(t::Tuple, ts::Tuple...) = (tail(t), tails(ts...)...)
map(f, ::Tuple{}, ts::Tuple...) = ()
map(f, ts::Tuple...) = (f(heads(ts...)...), map(f, tails(ts...)...)...)
map(f, ts::Tuple...) = ([f([t[i] for t in ts]...) for i in 1:length(ts[1])]...)

# type-stable padding
fill_to_length{N}(t::Tuple, val, ::Type{Val{N}}) = _ftl((), val, Val{N}, t...)
Expand Down

0 comments on commit 1a2da9e

Please sign in to comment.