Reduce size of FnPtr.
This commit is contained in:
parent
05fa8460a3
commit
5a3bbaa322
@ -1245,6 +1245,7 @@ mod tests {
|
|||||||
assert_eq!(size_of::<Option<crate::ast::Expr>>(), 16);
|
assert_eq!(size_of::<Option<crate::ast::Expr>>(), 16);
|
||||||
assert_eq!(size_of::<crate::ast::Stmt>(), 32);
|
assert_eq!(size_of::<crate::ast::Stmt>(), 32);
|
||||||
assert_eq!(size_of::<Option<crate::ast::Stmt>>(), 32);
|
assert_eq!(size_of::<Option<crate::ast::Stmt>>(), 32);
|
||||||
|
assert_eq!(size_of::<crate::FnPtr>(), 32);
|
||||||
assert_eq!(size_of::<crate::Scope>(), 48);
|
assert_eq!(size_of::<crate::Scope>(), 48);
|
||||||
assert_eq!(size_of::<crate::LexError>(), 56);
|
assert_eq!(size_of::<crate::LexError>(), 56);
|
||||||
assert_eq!(size_of::<crate::ParseError>(), 16);
|
assert_eq!(size_of::<crate::ParseError>(), 16);
|
||||||
|
@ -10,11 +10,12 @@ use crate::stdlib::{
|
|||||||
iter::empty,
|
iter::empty,
|
||||||
mem,
|
mem,
|
||||||
string::String,
|
string::String,
|
||||||
|
vec::Vec,
|
||||||
};
|
};
|
||||||
use crate::token::is_valid_identifier;
|
use crate::token::is_valid_identifier;
|
||||||
use crate::{
|
use crate::{
|
||||||
calc_script_fn_hash, Dynamic, Engine, EvalAltResult, EvalContext, ImmutableString, Module,
|
calc_script_fn_hash, Dynamic, Engine, EvalAltResult, EvalContext, ImmutableString, Module,
|
||||||
Position, StaticVec,
|
Position,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(not(feature = "sync"))]
|
#[cfg(not(feature = "sync"))]
|
||||||
@ -237,7 +238,7 @@ pub type FnCallArgs<'a> = [&'a mut Dynamic];
|
|||||||
/// A general function pointer, which may carry additional (i.e. curried) argument values
|
/// A general function pointer, which may carry additional (i.e. curried) argument values
|
||||||
/// to be passed onto a function during a call.
|
/// to be passed onto a function during a call.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct FnPtr(ImmutableString, StaticVec<Dynamic>);
|
pub struct FnPtr(ImmutableString, Vec<Dynamic>);
|
||||||
|
|
||||||
impl FnPtr {
|
impl FnPtr {
|
||||||
/// Create a new function pointer.
|
/// Create a new function pointer.
|
||||||
@ -247,10 +248,7 @@ impl FnPtr {
|
|||||||
}
|
}
|
||||||
/// Create a new function pointer without checking its parameters.
|
/// Create a new function pointer without checking its parameters.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn new_unchecked(
|
pub(crate) fn new_unchecked(name: impl Into<ImmutableString>, curry: Vec<Dynamic>) -> Self {
|
||||||
name: impl Into<ImmutableString>,
|
|
||||||
curry: StaticVec<Dynamic>,
|
|
||||||
) -> Self {
|
|
||||||
Self(name.into(), curry)
|
Self(name.into(), curry)
|
||||||
}
|
}
|
||||||
/// Get the name of the function.
|
/// Get the name of the function.
|
||||||
@ -265,7 +263,7 @@ impl FnPtr {
|
|||||||
}
|
}
|
||||||
/// Get the underlying data of the function pointer.
|
/// Get the underlying data of the function pointer.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn take_data(self) -> (ImmutableString, StaticVec<Dynamic>) {
|
pub(crate) fn take_data(self) -> (ImmutableString, Vec<Dynamic>) {
|
||||||
(self.0, self.1)
|
(self.0, self.1)
|
||||||
}
|
}
|
||||||
/// Get the curried arguments.
|
/// Get the curried arguments.
|
||||||
@ -320,9 +318,9 @@ impl FnPtr {
|
|||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.chain(arg_values.iter_mut().map(mem::take))
|
.chain(arg_values.iter_mut().map(mem::take))
|
||||||
.collect::<StaticVec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let mut args = args_data.iter_mut().collect::<StaticVec<_>>();
|
let mut args = args_data.iter_mut().collect::<Vec<_>>();
|
||||||
|
|
||||||
let is_method = this_ptr.is_some();
|
let is_method = this_ptr.is_some();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user