Skip to content

Switch from a mutation loop to a generator in a make_idx path #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/componentarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,16 @@ end
# Builds up data vector and returns appropriate AbstractAxis type for each input type
function make_idx(data, nt::Union{NamedTuple, AbstractDict}, last_val)
len = recursive_length(nt)
kvs = []
lv = 0
for (k, v) in pairs(nt)
(_, val) = make_idx(data, v, lv)
push!(kvs, k => val)
lv = val
end
return (data, ViewAxis(last_index(last_val) .+ (1:len), (;kvs...)))
lv = Ref(0) # workaround for https://github.com/JuliaLang/julia/issues/15276
kvs = (;(
k => begin
inds = make_idx(data, v, lv[])[2]
lv[] = last_index(inds)
inds
end
for (k, v) in pairs(nt)
)...)
return (data, ViewAxis(last_index(last_val) .+ (1:len), kvs))
end
function make_idx(data, pair::Pair, last_val)
data, ax = make_idx(data, pair.second, last_val)
Expand Down