Use generics instead of dynamic dispatch
fu5ha opened this issue · 3 comments
fu5ha commented
In many places currently, the code uses dynamic dispatch when you could instead use generics and static dispatch. For example, the render method
pub fn render(
scene: &Scene,
camera: &Arc<Camera + Send + Sync>,
sampler: &mut Box<Sampler + Send + Sync>,
integrator: &mut Box<SamplerIntegrator + Send + Sync>,
num_threads: u8,
) {
could instead be
pub fn render<SC, SA, I> (
scene: &SC,
camera: &Arc<Camera + Send + Sync>,
sampler: &mut SA,
integrator: &mut I,
num_threads: u8,
)
where
SC: Scene + Send + Sync,
SA: SamplerIntegrater + Send + Sync,
I: Integrator + Send + Sync
{
//....
}
wahn commented
Thanks for the suggestion. I will look into it ...
abusch commented
This is usually not possible because the concrete type of most of the arguments, such as the Integrator, isn't known at compile time. It is only known at runtime after parsing the scene file...