Skip to content

Commit

Permalink
Use if-else instead of dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Mar 15, 2024
1 parent be4a7fd commit 5e85c7c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
# Use recursion to avoid inference bail-out in `map`
#adapt_structure(to, xs::Union{Tuple,NamedTuple}) = map(adapt(to), xs)
adapt_structure(to, xs::NamedTuple) = map(adapt(to), xs)
adapt_structure(to, xs::Tuple) = map(adapt(to), xs)
adapt_structure(to, xs::NTuple{N}) where {N} = map(adapt(to), xs)
# Specialize on small Tuples
for N in 1:10
@eval adapt_structure(to, xs::NTuple{$N}) = _adapt_tuple_structure(to, xs)
function adapt_structure(to, xs::Tuple)
if length(xs) 20
_adapt_tuple_structure(to, xs)
else
map(adapt(to), xs)
end
end
_adapt_tuple_structure(to, xs::Tuple) =
(adapt(to, first(xs)), _adapt_tuple_structure(to, Base.tail(xs))...)
Expand Down

0 comments on commit 5e85c7c

Please sign in to comment.