Skip to content

Commit 79c6b64

Browse files
author
Miha Zgubic
committed
use generated function instead
1 parent e20ab52 commit 79c6b64

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

src/to_vec.jl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@ end
2121
# Base case -- if x is already a Vector{<:Real} there's no conversion necessary.
2222
to_vec(x::Vector{<:Real}) = (x, identity)
2323

24-
# get around the outer constructors
25-
macro _force_construct(T, argsplat_ex)
26-
@assert argsplat_ex.head == :(...)
27-
args = first(argsplat_ex.args)
28-
return esc(Expr(:splatnew, T, args))
29-
end
24+
# get around the constructors and make the type directly
25+
@generated _force_construct(T, args...) = Expr(:new, :T, Any[:(args[$i]) for i in 1:length(args)]...)
3026

3127
# Fallback method for `to_vec`. Won't always do what you wanted, but should be fine a decent
3228
# chunk of the time.
@@ -45,7 +41,7 @@ function to_vec(x::T) where {T}
4541
try
4642
T(values...)
4743
catch MethodError
48-
return @_force_construct(T, values...)
44+
return _force_construct(T, values...)
4945
end
5046
end
5147
return v, structtype_from_vec

0 commit comments

Comments
 (0)