Skip to content

Commit

Permalink
perf(func_idx): use import_count instead of hard sub env.memory
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop authored and atenjin committed Jun 2, 2021
1 parent dc62405 commit 84f090a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"]
Expand Down
18 changes: 4 additions & 14 deletions src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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();
{
Expand Down Expand Up @@ -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());
}
}
Expand Down

0 comments on commit 84f090a

Please sign in to comment.