Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
Improve performance of collect(tr)
Browse files Browse the repository at this point in the history
  • Loading branch information
cstjean committed Sep 12, 2017
1 parent 8768378 commit e250107
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/TraceCalls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,19 @@ is one of `functions` """
filter_func(functions::Vector, tr::Trace) = filter(tr->tr.func in functions, tr)
filter_func(func::Function, tr::Trace) = filter_func([func], tr)

function collect_!(trace_list, tr::Trace)
push!(trace_list, tr)
for sub in tr.called
collect_!(trace_list, sub)
end
end

""" `collect(tr::Trace)` returns a vector of all `Trace` objects within `tr`. """
Base.collect(tr::Trace) = Trace[tr; mapreduce(collect, vcat, [], tr.called)]
function Base.collect(tr::Trace)
trace_list = Trace[]
collect_!(trace_list, tr)
trace_list
end

""" `prune(tr::Trace, max_depth::Int=0, max_length::Int=1000000000)` prunes the Trace-tree
maximum tree depth, and maximum length (number of branches in each node).
Expand Down

0 comments on commit e250107

Please sign in to comment.