Skip to content

Commit a12d34a

Browse files
author
Christopher Doris
committed
tuple conversion more type stable
1 parent 0f99749 commit a12d34a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/concrete/tuple.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ function pytuple_fromiter(xs)
3030
end
3131
end
3232

33+
@generated function pytuple_fromiter(xs::Tuple)
34+
n = length(xs.parameters)
35+
code = []
36+
push!(code, :(ans = pynulltuple($n)))
37+
for i in 1:n
38+
push!(code, :(pytuple_setitem(ans, $(i-1), xs[$i])))
39+
end
40+
push!(code, :(return ans))
41+
return Expr(:block, code...)
42+
end
43+
3344
"""
3445
pytuple(x=())
3546

0 commit comments

Comments
 (0)