Open MaikKlein opened 6 years ago
The above sounds good to me. Please feel free to modify and send pull requests! :)
Just keep it as Arc<AtomicUsize>
would be fine for me. Let's change it to a more generic solution when demanded.
Nit: append()
sounds more like attaching at the end of the builder; we actually want merge()
.
I currently want to multi-thread my code generation, but Builder is inherently mutable. The simple solution would be to just wrap it in a mutex, but that would kill the performance.
One solution that I am thinking of is to create a separate builder object for every node that I traverse, then I would return the builder object and merge them together in the correct order.
The only problem that I see are the ids. If I would want to split the builder object into many small builder objects I would need to keep track of the correct IDs.
One solution would be to use an
Arc<AtomicUsize>
, this could also made generic.And and
append
function to merge them together.builder.append(other_builder);
What are your thoughts?