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=syrusakbary 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 <[email protected]>
  • Loading branch information
bors[bot] and Hywan authored Mar 2, 2021
2 parents 3bab215 + a5347fe commit 77a35a3
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 77a35a3

Please sign in to comment.