chore: remove duplicated arc (#13871)

This commit is contained in:
yjh
2023-04-11 18:42:49 +08:00
committed by GitHub
parent a53110f929
commit 271d65eae7
4 changed files with 15 additions and 15 deletions
+3 -3
View File
@@ -48,7 +48,7 @@ fn initialize(
_tmpdir: &mut Option<tempfile::TempDir>,
runtime: &[u8],
method: Method,
) -> Arc<dyn WasmModule> {
) -> Box<dyn WasmModule> {
let blob = RuntimeBlob::uncompress_if_needed(runtime).unwrap();
let host_functions = sp_io::SubstrateHostFunctions::host_functions();
let allow_missing_func_imports = true;
@@ -60,7 +60,7 @@ fn initialize(
host_functions,
allow_missing_func_imports,
)
.map(|runtime| -> Arc<dyn WasmModule> { Arc::new(runtime) }),
.map(|runtime| -> Box<dyn WasmModule> { Box::new(runtime) }),
Method::Compiled { instantiation_strategy, precompile } => {
let config = sc_executor_wasmtime::Config {
allow_missing_func_imports,
@@ -98,7 +98,7 @@ fn initialize(
} else {
sc_executor_wasmtime::create_runtime::<sp_io::SubstrateHostFunctions>(blob, config)
}
.map(|runtime| -> Arc<dyn WasmModule> { Arc::new(runtime) })
.map(|runtime| -> Box<dyn WasmModule> { Box::new(runtime) })
},
}
.unwrap()
+1 -1
View File
@@ -320,7 +320,7 @@ where
) -> Result<R>
where
F: FnOnce(
AssertUnwindSafe<&Arc<dyn WasmModule>>,
AssertUnwindSafe<&dyn WasmModule>,
AssertUnwindSafe<&mut dyn WasmInstance>,
Option<&RuntimeVersion>,
AssertUnwindSafe<&mut dyn Externalities>,
@@ -483,7 +483,7 @@ fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) {
fn mk_test_runtime(
wasm_method: WasmExecutionMethod,
pages: HeapAllocStrategy,
) -> Arc<dyn WasmModule> {
) -> Box<dyn WasmModule> {
let blob = RuntimeBlob::uncompress_if_needed(wasm_binary_unwrap())
.expect("failed to create a runtime blob out of test runtime");
+10 -10
View File
@@ -71,14 +71,14 @@ struct VersionedRuntimeId {
/// A Wasm runtime object along with its cached runtime version.
struct VersionedRuntime {
/// Shared runtime that can spawn instances.
module: Arc<dyn WasmModule>,
module: Box<dyn WasmModule>,
/// Runtime version according to `Core_version` if any.
version: Option<RuntimeVersion>,
// TODO: Remove this once the legacy instance reuse instantiation strategy
// for `wasmtime` is gone, as this only makes sense with that particular strategy.
/// Cached instance pool.
instances: Arc<Vec<Mutex<Option<Box<dyn WasmInstance>>>>>,
instances: Vec<Mutex<Option<Box<dyn WasmInstance>>>>,
}
impl VersionedRuntime {
@@ -86,7 +86,7 @@ impl VersionedRuntime {
fn with_instance<R, F>(&self, ext: &mut dyn Externalities, f: F) -> Result<R, Error>
where
F: FnOnce(
&Arc<dyn WasmModule>,
&dyn WasmModule,
&mut dyn WasmInstance,
Option<&RuntimeVersion>,
&mut dyn Externalities,
@@ -106,7 +106,7 @@ impl VersionedRuntime {
.map(|r| Ok((r, false)))
.unwrap_or_else(|| self.module.new_instance().map(|i| (i, true)))?;
let result = f(&self.module, &mut *instance, self.version.as_ref(), ext);
let result = f(&*self.module, &mut *instance, self.version.as_ref(), ext);
if let Err(e) = &result {
if new_inst {
tracing::warn!(
@@ -142,7 +142,7 @@ impl VersionedRuntime {
// Allocate a new instance
let mut instance = self.module.new_instance()?;
f(&self.module, &mut *instance, self.version.as_ref(), ext)
f(&*self.module, &mut *instance, self.version.as_ref(), ext)
},
}
}
@@ -228,7 +228,7 @@ impl RuntimeCache {
where
H: HostFunctions,
F: FnOnce(
&Arc<dyn WasmModule>,
&dyn WasmModule,
&mut dyn WasmInstance,
Option<&RuntimeVersion>,
&mut dyn Externalities,
@@ -294,7 +294,7 @@ pub fn create_wasm_runtime_with_code<H>(
blob: RuntimeBlob,
allow_missing_func_imports: bool,
cache_path: Option<&Path>,
) -> Result<Arc<dyn WasmModule>, WasmError>
) -> Result<Box<dyn WasmModule>, WasmError>
where
H: HostFunctions,
{
@@ -312,7 +312,7 @@ where
H::host_functions(),
allow_missing_func_imports,
)
.map(|runtime| -> Arc<dyn WasmModule> { Arc::new(runtime) })
.map(|runtime| -> Box<dyn WasmModule> { Box::new(runtime) })
},
WasmExecutionMethod::Compiled { instantiation_strategy } =>
sc_executor_wasmtime::create_runtime::<H>(
@@ -333,7 +333,7 @@ where
},
},
)
.map(|runtime| -> Arc<dyn WasmModule> { Arc::new(runtime) }),
.map(|runtime| -> Box<dyn WasmModule> { Box::new(runtime) }),
}
}
@@ -448,7 +448,7 @@ where
let mut instances = Vec::with_capacity(max_instances);
instances.resize_with(max_instances, || Mutex::new(None));
Ok(VersionedRuntime { module: runtime, version, instances: Arc::new(instances) })
Ok(VersionedRuntime { module: runtime, version, instances })
}
#[cfg(test)]