diff --git a/base/tuple.jl b/base/tuple.jl index bc0d3c932b0c4..927bc7bc953b4 100644 --- a/base/tuple.jl +++ b/base/tuple.jl @@ -20,7 +20,7 @@ endof(t::Tuple) = length(t) size(t::Tuple, d) = d==1 ? length(t) : throw(ArgumentError("invalid tuple dimension $d")) getindex(t::Tuple, i::Int) = getfield(t, i) getindex(t::Tuple, i::Real) = getfield(t, convert(Int, i)) -getindex(t::Tuple, r::AbstractArray{<:Any,1}) = tuple([t[ri] for ri in r]...) +getindex(t::Tuple, r::AbstractArray{<:Any,1}) = (n = length(eachindex(r)); ntuple(i->t[r[i]], n)) getindex(t::Tuple, b::AbstractArray{Bool,1}) = length(b) == length(t) ? getindex(t,find(b)) : throw(BoundsError(t, b)) # returns new tuple; N.B.: becomes no-op if i is out-of-bounds @@ -160,7 +160,8 @@ 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, t1::Tuple, t2::Tuple, ts::Tuple...) = (f(heads(t1, t2, ts...)...), map(f, tails(t1, t2, ts...)...)...) +map(f, t1::Tuple, t2::Tuple, ts::Tuple...) = (@_inline_meta; + (f(heads(t1, t2, ts...)...), map(f, tails(t1, t2, ts...)...)...)) # type-stable padding