Skip to content

Commit

Permalink
Merge #2141
Browse files Browse the repository at this point in the history
2141: feat(types) Avoid allocating a `Vec` when calling `FunctionType::new` r=Hywan a=Hywan

# Description

Sequel of #2036. We can go further by defining `Params` and `Results` of `FunctionType::new` as `Into<Box<[Type]>>` directly rather than `Into<Vec<Type>>`. It simplifies the code: `params.into()` rather than `params.into().into_boxed_slice()`. I assume it doesn't allocate an intermediate vector.

Since `From<Box<[T]>>` is implemented for `Vec<T>`, I reckon it's not a BC break.

# Review

- [ ] ~Add a short description of the the change to the CHANGELOG.md file~ not necessary


Co-authored-by: Ivan Enderlin <ivan@mnt.io>
  • Loading branch information
bors[bot] and Hywan authored Feb 26, 2021
2 parents d1bd9ea + a5347fe commit 5f6b8ca
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
14 changes: 0 additions & 14 deletions lib/api/src/import_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,6 @@ impl IntoIterator for ImportObject {

impl fmt::Debug for ImportObject {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
enum SecretOption {
None,
Some,
}

impl fmt::Debug for SecretOption {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::None => write!(f, "None"),
Self::Some => write!(f, "Some(...)"),
}
}
}

enum SecretMap {
Empty,
Some(usize),
Expand Down
8 changes: 4 additions & 4 deletions lib/wasmer-types/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ impl FunctionType {
/// Creates a new Function Type with the given parameter and return types.
pub fn new<Params, Returns>(params: Params, returns: Returns) -> Self
where
Params: Into<Vec<Type>>,
Returns: Into<Vec<Type>>,
Params: Into<Box<[Type]>>,
Returns: Into<Box<[Type]>>,
{
Self {
params: params.into().into_boxed_slice(),
results: returns.into().into_boxed_slice(),
params: params.into(),
results: returns.into(),
}
}

Expand Down

0 comments on commit 5f6b8ca

Please sign in to comment.