From 5a73b10ff8129a1cceb122a93200df1b185b5e78 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Tue, 11 Apr 2017 14:06:59 +0300 Subject: [PATCH] fix also for signature collection --- src/builder/module.rs | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/src/builder/module.rs b/src/builder/module.rs index 3aded91..fb5dbd6 100644 --- a/src/builder/module.rs +++ b/src/builder/module.rs @@ -144,6 +144,7 @@ impl ModuleBuilder where F: Invoke { fn resolve_type_ref(&mut self, signature: code::Signature) -> u32 { match signature { code::Signature::Inline(func_type) => { + // todo: maybe search for existing type self.module.types.types_mut().push(elements::Type::Function(func_type)); self.module.types.types().len() as u32 - 1 } @@ -161,27 +162,9 @@ impl ModuleBuilder where F: Invoke { /// Push signatures in the module, returning corresponding indices of pushed signatures pub fn push_signatures(&mut self, signatures: code::SignatureBindings) -> Vec { - let mut result = Vec::new(); - - // todo: maybe reuse existing types with the equal signatures - let raw_functions: Vec = signatures.into_iter().map(|binding| - match binding { - code::Signature::Inline(func_type) => { - self.module.types.types_mut().push(elements::Type::Function(func_type)); - self.module.types.types().len() as u32 - 1 - } - code::Signature::TypeReference(type_ref) => { - type_ref - } - } - ).collect(); - - for function in raw_functions { - self.module.functions.entries_mut().push(elements::Func::new(function)); - result.push(self.module.functions.entries_mut().len() as u32 - 1); - } - - result + signatures.into_iter().map(|binding| + self.resolve_type_ref(binding) + ).collect() } pub fn function(self) -> FunctionBuilder {