From 84f090a9792508a5ab070c4f50ba8fca519930f4 Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 5 Jan 2021 16:33:50 +0800 Subject: [PATCH] perf(func_idx): use import_count instead of hard sub env.memory --- Cargo.toml | 2 -- src/module.rs | 18 ++++-------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7fef1689ae..ed3c9a72d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ libc = { version = "0.2.58", optional = true} errno = { version = "0.2.4", optional = true } downcast-rs = { version = "1.2.0", default-features = false } rustc-demangle = "0.1" -cfg-if = "1.0.0" [dev-dependencies] assert_matches = "1.1" @@ -58,7 +57,6 @@ core = [ # Useful for tests and if you need to minimize unsafe usage at the cost of performance on some # workloads. vec_memory = [] -substrate = [] [workspace] members = ["validation"] diff --git a/src/module.rs b/src/module.rs index 52a020d5dd..d1085e20e2 100644 --- a/src/module.rs +++ b/src/module.rs @@ -18,7 +18,7 @@ use alloc::{ use core::cell::{Ref, RefCell}; use core::fmt; use parity_wasm::elements::{ - External, IndexMap, InitExpr, Instruction, Internal, ResizableLimits, Type, + External, ImportCountType, IndexMap, InitExpr, Instruction, Internal, ResizableLimits, Type, }; use validation::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX}; @@ -310,18 +310,8 @@ impl ModuleInstance { &empty_index_map }); - // Count Imports - let imports_count = if let Some(imports) = module.import_section() { - cfg_if::cfg_if! { - if #[cfg(not(feature = "substrate"))] { - imports.entries().len() - } else { - imports.entries().len().checked_sub(1).unwrap_or(0) - } - } - } else { - 0 - }; + // Count Imported functions + let import_count = module.import_count(ImportCountType::Function); let code = loaded_module.code(); { @@ -349,7 +339,7 @@ impl ModuleInstance { let mut func_instance = FuncInstance::alloc_internal(Rc::downgrade(&instance.0), signature, func_body); if has_name_section { - if let Some(name) = function_names.get((index + imports_count) as u32) { + if let Some(name) = function_names.get((index + import_count) as u32) { func_instance = func_instance.set_info(index, name.to_string()); } }