@@ -21,6 +21,13 @@ function buildfromschema(initializer, ::Type{T}, ::Type{NT}) where {T, NT<:Tup}
2121 StructArray {T} (nt)
2222end
2323
24+ @static if VERSION < v " 1.2.0"
25+ @inline _getproperty (v:: Tuple , field) = getfield (v, field)
26+ @inline _getproperty (v, field) = getproperty (v, field)
27+ else
28+ const _getproperty = getproperty
29+ end
30+
2431function _foreachfield (names, L)
2532 vars = ntuple (i -> gensym (), L)
2633 exprs = Expr[]
@@ -29,19 +36,19 @@ function _foreachfield(names, L)
2936 end
3037 for field in names
3138 sym = QuoteNode (field)
32- args = [Expr (:call , :getcolumn , var, sym) for var in vars]
39+ args = [Expr (:call , :_getproperty , var, sym) for var in vars]
3340 push! (exprs, Expr (:call , :f , args... ))
3441 end
3542 push! (exprs, :(return nothing ))
3643 return Expr (:block , exprs... )
3744end
3845
39- @generated foreachfield (:: Type{<: NamedTuple{names} } , f, xs:: Vararg{Any, L} ) where {names, L} =
46+ @generated foreachfield_gen (:: NamedTuple{names} , f, xs:: Vararg{Any, L} ) where {names, L} =
4047 _foreachfield (names, L)
41- @generated foreachfield (:: Type{<: NTuple{N, Any} } , f, xs:: Vararg{Any, L} ) where {N, L} =
48+ @generated foreachfield_gen (:: NTuple{N, Any} , f, xs:: Vararg{Any, L} ) where {N, L} =
4249 _foreachfield (Base. OneTo (N), L)
4350
44- foreachfield (f, x:: T , xs... ) where {T} = foreachfield ( staticschema (T ), f, x, xs... )
51+ foreachfield (f, x:: StructArray , xs... ) = foreachfield_gen ( fieldarrays (x ), f, x, xs... )
4552
4653"""
4754`iscompatible(::Type{S}, ::Type{V}) where {S, V<:AbstractArray}`
@@ -126,11 +133,3 @@ hasfields(::Type{<:NTuple{N, Any}}) where {N} = true
126133hasfields (:: Type{<:NamedTuple{names}} ) where {names} = true
127134hasfields (:: Type{T} ) where {T} = ! isabstracttype (T)
128135hasfields (:: Union ) = false
129-
130- _setdiff (a, b) = setdiff (a, b)
131-
132- @inline _setdiff (:: Tuple{} , :: Tuple{} ) = ()
133- @inline _setdiff (:: Tuple{} , :: Tuple ) = ()
134- @inline _setdiff (a:: Tuple , :: Tuple{} ) = a
135- @inline _setdiff (a:: Tuple , b:: Tuple ) = _setdiff (_exclude (a, b[1 ]), Base. tail (b))
136- @inline _exclude (a, b) = foldl ((ys, x) -> x == b ? ys : (ys... , x), a; init = ())
0 commit comments