feat(c-api) Create OrderedResolver from a parallel iterator.

This patch adds `rayon` to `wasmer-c-api` so that we can create an
`OrderedResolver` from a `ParallelIterator`. For modules with a long
list of imports, it's interesting to parallelize the work.
This commit is contained in:
Ivan Enderlin
2021-08-16 14:38:33 +02:00
parent b72c6f59b1
commit 446a76312b
3 changed files with 15 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ use super::module::wasm_module_t;
use super::store::wasm_store_t;
use super::trap::wasm_trap_t;
use crate::ordered_resolver::OrderedResolver;
use rayon::prelude::*;
use std::mem;
use std::sync::Arc;
use wasmer_api::{Extern, Instance, InstantiationError};
@@ -51,8 +52,8 @@ pub unsafe extern "C" fn wasm_instance_new(
let module_import_count = module_imports.len();
let resolver: OrderedResolver = imports
.into_slice()
.map(|imports| imports.iter())
.unwrap_or_else(|| [].iter())
.map(|imports| imports.par_iter())
.unwrap_or_else(|| [].par_iter())
.map(|imp| Extern::from((&**imp).clone()))
.take(module_import_count)
.collect();