Restructure VMContext to eliminate a level of indirection.

This commit is contained in:
Dan Gohman
2019-01-03 11:02:37 -08:00
parent ff6776fe10
commit 3270369a69
10 changed files with 774 additions and 621 deletions

View File

@@ -159,7 +159,7 @@ impl CompiledModule {
/// Note that if only one instance of this module is needed, it may be more
/// efficient to call the top-level `instantiate`, since that avoids copying
/// the data initializers.
pub fn instantiate(&mut self) -> Result<Box<Instance>, InstantiationError> {
pub fn instantiate(&mut self) -> Result<Instance, InstantiationError> {
let data_initializers = self
.data_initializers
.iter()
@@ -205,7 +205,7 @@ pub fn instantiate(
compiler: &mut Compiler,
data: &[u8],
resolver: &mut Resolver,
) -> Result<Box<Instance>, SetupError> {
) -> Result<Instance, SetupError> {
let raw = RawCompiledModule::new(compiler, data, resolver)?;
Instance::new(

View File

@@ -7,7 +7,6 @@ use action::{ActionError, ActionOutcome, RuntimeValue};
use compiler::Compiler;
use cranelift_entity::PrimaryMap;
use resolver::Resolver;
use std::boxed::Box;
use std::collections::HashMap;
use std::string::String;
use wasmtime_runtime::{Export, Instance};
@@ -26,7 +25,7 @@ pub struct Namespace {
names: HashMap<String, InstanceIndex>,
/// The instances, available by index.
instances: PrimaryMap<InstanceIndex, Box<Instance>>,
instances: PrimaryMap<InstanceIndex, Instance>,
}
impl Namespace {
@@ -40,11 +39,7 @@ impl Namespace {
/// Install a new `Instance` in this `Namespace`, optionally with the
/// given name, and return its index.
pub fn instance(
&mut self,
instance_name: Option<&str>,
instance: Box<Instance>,
) -> InstanceIndex {
pub fn instance(&mut self, instance_name: Option<&str>, instance: Instance) -> InstanceIndex {
let index = self.instances.push(instance);
if let Some(instance_name) = instance_name {
self.names.insert(instance_name.into(), index);