Skip to content

Commit

Permalink
Always use run-length encoding of types when generating code
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Sep 26, 2018
1 parent 543cd3c commit 87c74d2
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,25 @@ function eachcolumn end

@inline function eachcolumn(f::Base.Callable, sch::Schema{names, types}, row, args...) where {names, types}
if @generated
if length(names) < 100
b = Expr(:block, Any[:(f(getproperty(row, $(Meta.QuoteNode(names[i]))), $i, $(Meta.QuoteNode(names[i])), args...)) for i = 1:length(names)]...)
else
rle = runlength(types)
if length(rle) < 100
block = Expr(:block)
i = 1
for (T, len) in rle
push!(block.args, quote
for j = 0:$(len-1)
f(getproperty(row, $T, $i + j, names[$i + j]), $i + j, names[$i + j], args...)
end
end)
i += len
end
b = block
else
b = quote
for (i, nm) in enumerate(names)
f(getproperty(row, fieldtype(types, i), i, nm), i, nm, args...)
rle = runlength(types)
if length(rle) < 100
block = Expr(:block)
i = 1
for (T, len) in rle
push!(block.args, quote
for j = 0:$(len-1)
f(getproperty(row, $T, $i + j, names[$i + j]), $i + j, names[$i + j], args...)
end
return
end)
i += len
end
b = block
else
b = quote
for (i, nm) in enumerate(names)
f(getproperty(row, fieldtype(types, i), i, nm), i, nm, args...)
end
return
end
end
# println(b)
Expand Down

0 comments on commit 87c74d2

Please sign in to comment.