Only require str in new_with_name (#796)

* Only require `str` in `new_with_name`

It's a bit more idiomatic to have APIs require `&str` rather than
`String`, and the allocation doesn't matter much here since creating a
`Module` is pretty expensive anyway.

* Update a test
This commit is contained in:
Alex Crichton
2020-01-10 13:17:41 -06:00
committed by GitHub
parent 6571fb8f4f
commit 6b3ee47915
4 changed files with 14 additions and 20 deletions

View File

@@ -60,7 +60,7 @@ impl<'data> RawCompiledModule<'data> {
fn new(
compiler: &mut Compiler,
data: &'data [u8],
module_name: Option<String>,
module_name: Option<&str>,
resolver: &mut dyn Resolver,
debug_info: bool,
) -> Result<Self, SetupError> {
@@ -76,7 +76,7 @@ impl<'data> RawCompiledModule<'data> {
None
};
translation.module.name = module_name;
translation.module.name = module_name.map(|s| s.to_string());
let (allocated_functions, jt_offsets, relocations, dbg_image) = compiler.compile(
&translation.module,
@@ -155,7 +155,7 @@ impl CompiledModule {
pub fn new<'data>(
compiler: &mut Compiler,
data: &'data [u8],
module_name: Option<String>,
module_name: Option<&str>,
resolver: &mut dyn Resolver,
global_exports: Rc<RefCell<HashMap<String, Option<Export>>>>,
debug_info: bool,
@@ -263,7 +263,7 @@ impl OwnedDataInitializer {
pub fn instantiate(
compiler: &mut Compiler,
data: &[u8],
module_name: Option<String>,
module_name: Option<&str>,
resolver: &mut dyn Resolver,
global_exports: Rc<RefCell<HashMap<String, Option<Export>>>>,
debug_info: bool,