Change ScriptFnDef to use ImmutableString.
This commit is contained in:
parent
b4b7abdcb0
commit
a58207aaa9
@ -456,7 +456,7 @@ fn optimize_expr(expr: Expr, state: &mut State) -> Expr {
|
||||
// "xxx" in "xxxxx"
|
||||
(Expr::StringConstant(a), Expr::StringConstant(b)) => {
|
||||
state.set_dirty();
|
||||
if b.0.contains(a.0.as_ref()) { Expr::True(a.1) } else { Expr::False(a.1) }
|
||||
if b.0.contains(a.0.as_str()) { Expr::True(a.1) } else { Expr::False(a.1) }
|
||||
}
|
||||
// 'x' in "xxxxx"
|
||||
(Expr::CharConstant(a), Expr::StringConstant(b)) => {
|
||||
@ -560,7 +560,7 @@ fn optimize_expr(expr: Expr, state: &mut State) -> Expr {
|
||||
let has_script_fn = state.lib.iter_fn().find(|(_, _, _, f)| {
|
||||
if !f.is_script() { return false; }
|
||||
let fn_def = f.get_fn_def();
|
||||
&fn_def.name == name && (args.len()..=args.len() + 1).contains(&fn_def.params.len())
|
||||
fn_def.name.as_str() == name && (args.len()..=args.len() + 1).contains(&fn_def.params.len())
|
||||
}).is_some();
|
||||
|
||||
#[cfg(feature = "no_function")]
|
||||
|
@ -346,7 +346,7 @@ impl fmt::Display for FnAccess {
|
||||
#[derive(Debug, Clone, Hash)]
|
||||
pub struct ScriptFnDef {
|
||||
/// Function name.
|
||||
pub name: String,
|
||||
pub name: ImmutableString,
|
||||
/// Function access mode.
|
||||
pub access: FnAccess,
|
||||
/// Names of function parameters.
|
||||
@ -2852,7 +2852,7 @@ fn parse_fn(
|
||||
let params = params.into_iter().map(|(p, _)| p).collect();
|
||||
|
||||
Ok(ScriptFnDef {
|
||||
name,
|
||||
name: name.into(),
|
||||
access,
|
||||
params,
|
||||
body,
|
||||
@ -2940,7 +2940,7 @@ fn parse_anon_fn(
|
||||
let hash = s.finish();
|
||||
|
||||
// Create unique function name
|
||||
let fn_name = format!("{}{}", FN_ANONYMOUS, hash);
|
||||
let fn_name: ImmutableString = format!("{}{:16x}", FN_ANONYMOUS, hash).into();
|
||||
|
||||
let script = ScriptFnDef {
|
||||
name: fn_name.clone(),
|
||||
@ -2950,7 +2950,7 @@ fn parse_anon_fn(
|
||||
pos: settings.pos,
|
||||
};
|
||||
|
||||
let expr = Expr::FnPointer(Box::new((fn_name.into(), settings.pos)));
|
||||
let expr = Expr::FnPointer(Box::new((fn_name, settings.pos)));
|
||||
|
||||
Ok((expr, script))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user