From 5e85c7c02322584784d53d03204c41235412183d Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Fri, 15 Mar 2024 09:20:47 -0400 Subject: [PATCH] Use if-else instead of dispatch --- src/base.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/base.jl b/src/base.jl index 8e966ff..541c834 100644 --- a/src/base.jl +++ b/src/base.jl @@ -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))...)