diff --git a/codegen/src/function.rs b/codegen/src/function.rs index f69ed3cd..e98785e7 100644 --- a/codegen/src/function.rs +++ b/codegen/src/function.rs @@ -591,9 +591,8 @@ impl ExportedFn { syn::Ident::new(&format!("rhai_fn_{}", self.name()), self.name().span()); let impl_block = self.generate_impl("Token"); let callable_block = self.generate_callable("Token"); - let input_names_block = self.generate_input_names("Token"); + let param_names_block = self.generate_param_names("Token"); let input_types_block = self.generate_input_types("Token"); - let return_type_block = self.generate_return_type("Token"); let dyn_result_fn_block = self.generate_dynamic_fn(); let vis = self.visibility; quote! { @@ -603,10 +602,8 @@ impl ExportedFn { struct Token(); #impl_block #callable_block - #input_names_block + #param_names_block #input_types_block - #return_type_block - #[allow(unused)] #dyn_result_fn_block } } @@ -650,6 +647,8 @@ impl ExportedFn { } } else { quote_spanned! { return_span => + #[allow(unused)] + #[inline(always)] pub #dynamic_signature { Ok(Dynamic::from(#name(#(#arguments),*))) } @@ -664,21 +663,23 @@ impl ExportedFn { self.name().span(), ); quote! { + #[inline(always)] pub fn #callable_fn_name() -> CallableFunction { #token_name().into() } } } - pub fn generate_input_names(&self, on_type_name: &str) -> proc_macro2::TokenStream { + pub fn generate_param_names(&self, on_type_name: &str) -> proc_macro2::TokenStream { let token_name: syn::Ident = syn::Ident::new(on_type_name, self.name().span()); - let input_names_fn_name: syn::Ident = syn::Ident::new( - &format!("{}_input_names", on_type_name.to_lowercase()), + let param_names_fn_name: syn::Ident = syn::Ident::new( + &format!("{}_param_names", on_type_name.to_lowercase()), self.name().span(), ); quote! { - pub fn #input_names_fn_name() -> Box<[&'static str]> { - #token_name().input_names() + #[inline(always)] + pub fn #param_names_fn_name() -> Box<[&'static str]> { + #token_name().param_names() } } } @@ -690,25 +691,13 @@ impl ExportedFn { self.name().span(), ); quote! { + #[inline(always)] pub fn #input_types_fn_name() -> Box<[TypeId]> { #token_name().input_types() } } } - pub fn generate_return_type(&self, on_type_name: &str) -> proc_macro2::TokenStream { - let token_name: syn::Ident = syn::Ident::new(on_type_name, self.name().span()); - let return_type_fn_name: syn::Ident = syn::Ident::new( - &format!("{}_return_type", on_type_name.to_lowercase()), - self.name().span(), - ); - quote! { - pub fn #return_type_fn_name() -> &'static str { - #token_name().return_type() - } - } - } - pub fn generate_impl(&self, on_type_name: &str) -> proc_macro2::TokenStream { let sig_name = self.name().clone(); let arg_count = self.arg_count(); @@ -885,24 +874,22 @@ impl ExportedFn { let type_name = syn::Ident::new(on_type_name, proc_macro2::Span::call_site()); quote! { impl PluginFunction for #type_name { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), #arg_count, "wrong arg count: {} != {}", args.len(), #arg_count); #(#unpack_statements)* #return_expr } - fn is_method_call(&self) -> bool { #is_method_call } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { Box::new(#type_name()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec![#(#input_type_names),*].into_boxed_slice() + #[inline(always)] fn is_method_call(&self) -> bool { #is_method_call } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(#type_name()) } + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec![#(#input_type_names,)* #return_type].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![#(#input_type_exprs),*].into_boxed_slice() } - fn return_type(&self) -> &'static str { - #return_type - } } } } diff --git a/codegen/src/lib.rs b/codegen/src/lib.rs index 7ba9e874..a8bc11e8 100644 --- a/codegen/src/lib.rs +++ b/codegen/src/lib.rs @@ -340,7 +340,7 @@ pub fn set_exported_fn(args: proc_macro::TokenStream) -> proc_macro::TokenStream let gen_mod_path = crate::register::generated_module_path(&rust_mod_path); let tokens = quote! { #module_expr.set_fn(#export_name, FnNamespace::Internal, FnAccess::Public, - Some(#gen_mod_path::token_input_names().as_ref()), + Some(#gen_mod_path::token_param_names().as_ref()), #gen_mod_path::token_input_types().as_ref(), #gen_mod_path::token_callable()); }; @@ -382,7 +382,7 @@ pub fn set_exported_global_fn(args: proc_macro::TokenStream) -> proc_macro::Toke let gen_mod_path = crate::register::generated_module_path(&rust_mod_path); let tokens = quote! { #module_expr.set_fn(#export_name, FnNamespace::Global, FnAccess::Public, - Some(#gen_mod_path::token_input_names().as_ref()), + Some(#gen_mod_path::token_param_names().as_ref()), #gen_mod_path::token_input_types().as_ref(), #gen_mod_path::token_callable()); }; diff --git a/codegen/src/rhai_module.rs b/codegen/src/rhai_module.rs index fc4bc82a..1b83a407 100644 --- a/codegen/src/rhai_module.rs +++ b/codegen/src/rhai_module.rs @@ -185,9 +185,8 @@ pub fn generate_body( }); gen_fn_tokens.push(function.generate_impl(&fn_token_name.to_string())); gen_fn_tokens.push(function.generate_callable(&fn_token_name.to_string())); - gen_fn_tokens.push(function.generate_input_names(&fn_token_name.to_string())); + gen_fn_tokens.push(function.generate_param_names(&fn_token_name.to_string())); gen_fn_tokens.push(function.generate_input_types(&fn_token_name.to_string())); - gen_fn_tokens.push(function.generate_return_type(&fn_token_name.to_string())); } let mut generate_fn_call = syn::parse2::(quote! { diff --git a/codegen/src/test/function.rs b/codegen/src/test/function.rs index 25a0886a..c0abce5b 100644 --- a/codegen/src/test/function.rs +++ b/codegen/src/test/function.rs @@ -277,39 +277,33 @@ mod generate_tests { use super::*; struct Token(); impl PluginFunction for Token { - fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 0usize, "wrong arg count: {} != {}", args.len(), 0usize); Ok(Dynamic::from(do_nothing())) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { Box::new(Token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec![].into_boxed_slice() + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(Token()) } + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["()"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "()" - } } - pub fn token_callable() -> CallableFunction { + #[inline(always)] pub fn token_callable() -> CallableFunction { Token().into() } - pub fn token_input_names() -> Box<[&'static str]> { - Token().input_names() + #[inline(always)] pub fn token_param_names() -> Box<[&'static str]> { + Token().param_names() } - pub fn token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn token_input_types() -> Box<[TypeId]> { Token().input_types() } - pub fn token_return_type() -> &'static str { - Token().return_type() - } #[allow(unused)] - pub fn dynamic_result_fn() -> Result > { + #[inline(always)] pub fn dynamic_result_fn() -> Result > { Ok(Dynamic::from(do_nothing())) } } @@ -331,6 +325,7 @@ mod generate_tests { use super::*; struct Token(); impl PluginFunction for Token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 1usize, "wrong arg count: {} != {}", args.len(), 1usize); @@ -338,33 +333,27 @@ mod generate_tests { Ok(Dynamic::from(do_something(arg0))) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { Box::new(Token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: usize"].into_boxed_slice() + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(Token()) } + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: usize", "()"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "()" - } } - pub fn token_callable() -> CallableFunction { + #[inline(always)] pub fn token_callable() -> CallableFunction { Token().into() } - pub fn token_input_names() -> Box<[&'static str]> { - Token().input_names() + #[inline(always)] pub fn token_param_names() -> Box<[&'static str]> { + Token().param_names() } - pub fn token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn token_input_types() -> Box<[TypeId]> { Token().input_types() } - pub fn token_return_type() -> &'static str { - Token().return_type() - } #[allow(unused)] - pub fn dynamic_result_fn(x: usize) -> Result > { + #[inline(always)] pub fn dynamic_result_fn(x: usize) -> Result > { Ok(Dynamic::from(do_something(x))) } } @@ -386,6 +375,7 @@ mod generate_tests { use super::*; struct Token(); impl PluginFunction for Token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 1usize, "wrong arg count: {} != {}", args.len(), 1usize); @@ -393,33 +383,27 @@ mod generate_tests { Ok(Dynamic::from(do_something(context, arg0))) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { Box::new(Token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: usize"].into_boxed_slice() + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(Token()) } + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: usize", "()"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "()" - } } - pub fn token_callable() -> CallableFunction { + #[inline(always)] pub fn token_callable() -> CallableFunction { Token().into() } - pub fn token_input_names() -> Box<[&'static str]> { - Token().input_names() + #[inline(always)] pub fn token_param_names() -> Box<[&'static str]> { + Token().param_names() } - pub fn token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn token_input_types() -> Box<[TypeId]> { Token().input_types() } - pub fn token_return_type() -> &'static str { - Token().return_type() - } #[allow(unused)] - pub fn dynamic_result_fn(context: NativeCallContext, x: usize) -> Result > { + #[inline(always)] pub fn dynamic_result_fn(context: NativeCallContext, x: usize) -> Result > { Ok(Dynamic::from(do_something(context, x))) } } @@ -444,39 +428,34 @@ mod generate_tests { use super::*; struct Token(); impl PluginFunction for Token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 0usize, "wrong arg count: {} != {}", args.len(), 0usize); Ok(Dynamic::from(return_dynamic())) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { Box::new(Token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec![].into_boxed_slice() + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(Token()) } + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["rhai::Dynamic"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "rhai::Dynamic" - } } - pub fn token_callable() -> CallableFunction { + #[inline(always)] pub fn token_callable() -> CallableFunction { Token().into() } - pub fn token_input_names() -> Box<[&'static str]> { - Token().input_names() + #[inline(always)] pub fn token_param_names() -> Box<[&'static str]> { + Token().param_names() } - pub fn token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn token_input_types() -> Box<[TypeId]> { Token().input_types() } - pub fn token_return_type() -> &'static str { - Token().return_type() - } #[allow(unused)] - pub fn dynamic_result_fn() -> Result > { + #[inline(always)] pub fn dynamic_result_fn() -> Result > { Ok(Dynamic::from(return_dynamic())) } } @@ -494,6 +473,7 @@ mod generate_tests { let expected_tokens = quote! { impl PluginFunction for TestStruct { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 1usize, "wrong arg count: {} != {}", args.len(), 1usize); @@ -501,18 +481,15 @@ mod generate_tests { Ok(Dynamic::from(do_something(arg0))) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { Box::new(TestStruct()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: usize"].into_boxed_slice() + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(TestStruct()) } + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: usize", "()"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "()" - } } }; @@ -532,6 +509,7 @@ mod generate_tests { use super::*; struct Token(); impl PluginFunction for Token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 2usize, "wrong arg count: {} != {}", args.len(), 2usize); @@ -540,34 +518,28 @@ mod generate_tests { Ok(Dynamic::from(add_together(arg0, arg1))) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { Box::new(Token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: usize", "y: usize"].into_boxed_slice() + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(Token()) } + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: usize", "y: usize", "usize"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::(), TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "usize" - } } - pub fn token_callable() -> CallableFunction { + #[inline(always)] pub fn token_callable() -> CallableFunction { Token().into() } - pub fn token_input_names() -> Box<[&'static str]> { - Token().input_names() + #[inline(always)] pub fn token_param_names() -> Box<[&'static str]> { + Token().param_names() } - pub fn token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn token_input_types() -> Box<[TypeId]> { Token().input_types() } - pub fn token_return_type() -> &'static str { - Token().return_type() - } #[allow(unused)] - pub fn dynamic_result_fn(x: usize, y: usize) -> Result > { + #[inline(always)] pub fn dynamic_result_fn(x: usize, y: usize) -> Result > { Ok(Dynamic::from(add_together(x, y))) } } @@ -589,6 +561,7 @@ mod generate_tests { use super::*; struct Token(); impl PluginFunction for Token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 2usize, "wrong arg count: {} != {}", args.len(), 2usize); @@ -602,34 +575,28 @@ mod generate_tests { Ok(Dynamic::from(increment(arg0, arg1))) } - fn is_method_call(&self) -> bool { true } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { Box::new(Token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut usize", "y: usize"].into_boxed_slice() + #[inline(always)] fn is_method_call(&self) -> bool { true } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(Token()) } + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: &mut usize", "y: usize", "()"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::(), TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "()" - } } - pub fn token_callable() -> CallableFunction { + #[inline(always)] pub fn token_callable() -> CallableFunction { Token().into() } - pub fn token_input_names() -> Box<[&'static str]> { - Token().input_names() + #[inline(always)] pub fn token_param_names() -> Box<[&'static str]> { + Token().param_names() } - pub fn token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn token_input_types() -> Box<[TypeId]> { Token().input_types() } - pub fn token_return_type() -> &'static str { - Token().return_type() - } #[allow(unused)] - pub fn dynamic_result_fn(x: &mut usize, y: usize) -> Result > { + #[inline(always)] pub fn dynamic_result_fn(x: &mut usize, y: usize) -> Result > { Ok(Dynamic::from(increment(x, y))) } } @@ -652,6 +619,7 @@ mod generate_tests { use super::*; struct Token(); impl PluginFunction for Token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 1usize, "wrong arg count: {} != {}", args.len(), 1usize); @@ -659,33 +627,27 @@ mod generate_tests { Ok(Dynamic::from(special_print(&arg0))) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { Box::new(Token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["message: &str"].into_boxed_slice() + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(Token()) } + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["message: &str", "()"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "()" - } } - pub fn token_callable() -> CallableFunction { + #[inline(always)] pub fn token_callable() -> CallableFunction { Token().into() } - pub fn token_input_names() -> Box<[&'static str]> { - Token().input_names() + #[inline(always)] pub fn token_param_names() -> Box<[&'static str]> { + Token().param_names() } - pub fn token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn token_input_types() -> Box<[TypeId]> { Token().input_types() } - pub fn token_return_type() -> &'static str { - Token().return_type() - } #[allow(unused)] - pub fn dynamic_result_fn(message: &str) -> Result > { + #[inline(always)] pub fn dynamic_result_fn(message: &str) -> Result > { Ok(Dynamic::from(special_print(message))) } } diff --git a/codegen/src/test/module.rs b/codegen/src/test/module.rs index 90cbedc2..61645c81 100644 --- a/codegen/src/test/module.rs +++ b/codegen/src/test/module.rs @@ -304,39 +304,34 @@ mod generate_tests { #[allow(non_camel_case_types)] struct get_mystic_number_token(); impl PluginFunction for get_mystic_number_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 0usize, "wrong arg count: {} != {}", args.len(), 0usize); Ok(Dynamic::from(get_mystic_number())) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(get_mystic_number_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec![].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["INT"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "INT" - } } - pub fn get_mystic_number_token_callable() -> CallableFunction { + #[inline(always)] pub fn get_mystic_number_token_callable() -> CallableFunction { get_mystic_number_token().into() } - pub fn get_mystic_number_token_input_names() -> Box<[&'static str]> { - get_mystic_number_token().input_names() + #[inline(always)] pub fn get_mystic_number_token_param_names() -> Box<[&'static str]> { + get_mystic_number_token().param_names() } - pub fn get_mystic_number_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn get_mystic_number_token_input_types() -> Box<[TypeId]> { get_mystic_number_token().input_types() } - pub fn get_mystic_number_token_return_type() -> &'static str { - get_mystic_number_token().return_type() - } } }; @@ -371,13 +366,15 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("add_one_to", FnNamespace::Global, FnAccess::Public, Some(&["x: INT", "INT"]), &[core::any::TypeId::of::()], + m.set_fn("add_one_to", FnNamespace::Global, FnAccess::Public, Some(&["x: INT", "INT"]), + &[core::any::TypeId::of::()], add_one_to_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] struct add_one_to_token(); impl PluginFunction for add_one_to_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 1usize, "wrong arg count: {} != {}", args.len(), 1usize); @@ -385,33 +382,27 @@ mod generate_tests { Ok(Dynamic::from(add_one_to(arg0))) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(add_one_to_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: INT"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: INT", "INT"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "INT" - } } - pub fn add_one_to_token_callable() -> CallableFunction { + #[inline(always)] pub fn add_one_to_token_callable() -> CallableFunction { add_one_to_token().into() } - pub fn add_one_to_token_input_names() -> Box<[&'static str]> { - add_one_to_token().input_names() + #[inline(always)] pub fn add_one_to_token_param_names() -> Box<[&'static str]> { + add_one_to_token().param_names() } - pub fn add_one_to_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn add_one_to_token_input_types() -> Box<[TypeId]> { add_one_to_token().input_types() } - pub fn add_one_to_token_return_type() -> &'static str { - add_one_to_token().return_type() - } } }; @@ -445,13 +436,15 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("add_one_to", FnNamespace::Internal, FnAccess::Public, Some(&["x: INT", "INT"]), &[core::any::TypeId::of::()], + m.set_fn("add_one_to", FnNamespace::Internal, FnAccess::Public, Some(&["x: INT", "INT"]), + &[core::any::TypeId::of::()], add_one_to_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] struct add_one_to_token(); impl PluginFunction for add_one_to_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 1usize, "wrong arg count: {} != {}", args.len(), 1usize); @@ -459,33 +452,27 @@ mod generate_tests { Ok(Dynamic::from(add_one_to(arg0))) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(add_one_to_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: INT"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: INT", "INT"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "INT" - } } - pub fn add_one_to_token_callable() -> CallableFunction { + #[inline(always)] pub fn add_one_to_token_callable() -> CallableFunction { add_one_to_token().into() } - pub fn add_one_to_token_input_names() -> Box<[&'static str]> { - add_one_to_token().input_names() + #[inline(always)] pub fn add_one_to_token_param_names() -> Box<[&'static str]> { + add_one_to_token().param_names() } - pub fn add_one_to_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn add_one_to_token_input_types() -> Box<[TypeId]> { add_one_to_token().input_types() } - pub fn add_one_to_token_return_type() -> &'static str { - add_one_to_token().return_type() - } } }; @@ -530,7 +517,8 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("add_n", FnNamespace::Internal, FnAccess::Public, Some(&["x: INT", "INT"]), &[core::any::TypeId::of::()], + m.set_fn("add_n", FnNamespace::Internal, FnAccess::Public, Some(&["x: INT", "INT"]), + &[core::any::TypeId::of::()], add_one_to_token().into()); m.set_fn("add_n", FnNamespace::Internal, FnAccess::Public, Some(&["x: INT", "y: INT", "INT"]), &[core::any::TypeId::of::(), core::any::TypeId::of::()], @@ -540,6 +528,7 @@ mod generate_tests { #[allow(non_camel_case_types)] struct add_one_to_token(); impl PluginFunction for add_one_to_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 1usize, "wrong arg count: {} != {}", args.len(), 1usize); @@ -547,37 +536,32 @@ mod generate_tests { Ok(Dynamic::from(add_one_to(arg0))) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(add_one_to_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: INT"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: INT", "INT"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "INT" - } } - pub fn add_one_to_token_callable() -> CallableFunction { + #[inline(always)] pub fn add_one_to_token_callable() -> CallableFunction { add_one_to_token().into() } - pub fn add_one_to_token_input_names() -> Box<[&'static str]> { - add_one_to_token().input_names() + #[inline(always)] pub fn add_one_to_token_param_names() -> Box<[&'static str]> { + add_one_to_token().param_names() } - pub fn add_one_to_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn add_one_to_token_input_types() -> Box<[TypeId]> { add_one_to_token().input_types() } - pub fn add_one_to_token_return_type() -> &'static str { - add_one_to_token().return_type() - } #[allow(non_camel_case_types)] struct add_n_to_token(); impl PluginFunction for add_n_to_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 2usize, "wrong arg count: {} != {}", args.len(), 2usize); @@ -586,34 +570,28 @@ mod generate_tests { Ok(Dynamic::from(add_n_to(arg0, arg1))) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(add_n_to_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: INT", "y: INT"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: INT", "y: INT", "INT"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::(), TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "INT" - } } - pub fn add_n_to_token_callable() -> CallableFunction { + #[inline(always)] pub fn add_n_to_token_callable() -> CallableFunction { add_n_to_token().into() } - pub fn add_n_to_token_input_names() -> Box<[&'static str]> { - add_n_to_token().input_names() + #[inline(always)] pub fn add_n_to_token_param_names() -> Box<[&'static str]> { + add_n_to_token().param_names() } - pub fn add_n_to_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn add_n_to_token_input_types() -> Box<[TypeId]> { add_n_to_token().input_types() } - pub fn add_n_to_token_return_type() -> &'static str { - add_n_to_token().return_type() - } } }; @@ -655,6 +633,7 @@ mod generate_tests { #[allow(non_camel_case_types)] struct add_together_token(); impl PluginFunction for add_together_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 2usize, "wrong arg count: {} != {}", args.len(), 2usize); @@ -663,34 +642,28 @@ mod generate_tests { Ok(Dynamic::from(add_together(arg0, arg1))) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(add_together_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: INT", "y: INT"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: INT", "y: INT", "INT"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::(), TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "INT" - } } - pub fn add_together_token_callable() -> CallableFunction { + #[inline(always)] pub fn add_together_token_callable() -> CallableFunction { add_together_token().into() } - pub fn add_together_token_input_names() -> Box<[&'static str]> { - add_together_token().input_names() + #[inline(always)] pub fn add_together_token_param_names() -> Box<[&'static str]> { + add_together_token().param_names() } - pub fn add_together_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn add_together_token_input_types() -> Box<[TypeId]> { add_together_token().input_types() } - pub fn add_together_token_return_type() -> &'static str { - add_together_token().return_type() - } } }; @@ -739,6 +712,7 @@ mod generate_tests { #[allow(non_camel_case_types)] struct add_together_token(); impl PluginFunction for add_together_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 2usize, "wrong arg count: {} != {}", args.len(), 2usize); @@ -747,34 +721,28 @@ mod generate_tests { Ok(Dynamic::from(add_together(arg0, arg1))) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(add_together_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: INT", "y: INT"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: INT", "y: INT", "INT"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::(), TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "INT" - } } - pub fn add_together_token_callable() -> CallableFunction { + #[inline(always)] pub fn add_together_token_callable() -> CallableFunction { add_together_token().into() } - pub fn add_together_token_input_names() -> Box<[&'static str]> { - add_together_token().input_names() + #[inline(always)] pub fn add_together_token_param_names() -> Box<[&'static str]> { + add_together_token().param_names() } - pub fn add_together_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn add_together_token_input_types() -> Box<[TypeId]> { add_together_token().input_types() } - pub fn add_together_token_return_type() -> &'static str { - add_together_token().return_type() - } } }; @@ -997,39 +965,34 @@ mod generate_tests { #[allow(non_camel_case_types)] struct get_mystic_number_token(); impl PluginFunction for get_mystic_number_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 0usize, "wrong arg count: {} != {}", args.len(), 0usize); Ok(Dynamic::from(get_mystic_number())) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(get_mystic_number_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec![].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["INT"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "INT" - } } - pub fn get_mystic_number_token_callable() -> CallableFunction { + #[inline(always)] pub fn get_mystic_number_token_callable() -> CallableFunction { get_mystic_number_token().into() } - pub fn get_mystic_number_token_input_names() -> Box<[&'static str]> { - get_mystic_number_token().input_names() + #[inline(always)] pub fn get_mystic_number_token_param_names() -> Box<[&'static str]> { + get_mystic_number_token().param_names() } - pub fn get_mystic_number_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn get_mystic_number_token_input_types() -> Box<[TypeId]> { get_mystic_number_token().input_types() } - pub fn get_mystic_number_token_return_type() -> &'static str { - get_mystic_number_token().return_type() - } } }; @@ -1094,14 +1057,15 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("print_out_to", FnNamespace::Internal, FnAccess::Public, - Some(&["x: &str", "()"]), &[core::any::TypeId::of::()], + m.set_fn("print_out_to", FnNamespace::Internal, FnAccess::Public, Some(&["x: &str", "()"]), + &[core::any::TypeId::of::()], print_out_to_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] struct print_out_to_token(); impl PluginFunction for print_out_to_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 1usize, "wrong arg count: {} != {}", args.len(), 1usize); @@ -1109,33 +1073,27 @@ mod generate_tests { Ok(Dynamic::from(print_out_to(&arg0))) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(print_out_to_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: &str"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: &str", "()"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "()" - } } - pub fn print_out_to_token_callable() -> CallableFunction { + #[inline(always)] pub fn print_out_to_token_callable() -> CallableFunction { print_out_to_token().into() } - pub fn print_out_to_token_input_names() -> Box<[&'static str]> { - print_out_to_token().input_names() + #[inline(always)] pub fn print_out_to_token_param_names() -> Box<[&'static str]> { + print_out_to_token().param_names() } - pub fn print_out_to_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn print_out_to_token_input_types() -> Box<[TypeId]> { print_out_to_token().input_types() } - pub fn print_out_to_token_return_type() -> &'static str { - print_out_to_token().return_type() - } } }; @@ -1169,14 +1127,15 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("print_out_to", FnNamespace::Internal, FnAccess::Public, - Some(&["x: String", "()"]), &[core::any::TypeId::of::()], + m.set_fn("print_out_to", FnNamespace::Internal, FnAccess::Public, Some(&["x: String", "()"]), + &[core::any::TypeId::of::()], print_out_to_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] struct print_out_to_token(); impl PluginFunction for print_out_to_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 1usize, "wrong arg count: {} != {}", args.len(), 1usize); @@ -1184,33 +1143,27 @@ mod generate_tests { Ok(Dynamic::from(print_out_to(arg0))) } - fn is_method_call(&self) -> bool { false } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { false } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(print_out_to_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: String"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: String", "()"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "()" - } } - pub fn print_out_to_token_callable() -> CallableFunction { + #[inline(always)] pub fn print_out_to_token_callable() -> CallableFunction { print_out_to_token().into() } - pub fn print_out_to_token_input_names() -> Box<[&'static str]> { - print_out_to_token().input_names() + #[inline(always)] pub fn print_out_to_token_param_names() -> Box<[&'static str]> { + print_out_to_token().param_names() } - pub fn print_out_to_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn print_out_to_token_input_types() -> Box<[TypeId]> { print_out_to_token().input_types() } - pub fn print_out_to_token_return_type() -> &'static str { - print_out_to_token().return_type() - } } }; @@ -1245,14 +1198,15 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("foo", FnNamespace::Internal, FnAccess::Public, - Some(&["x: &mut FLOAT", "y: INT", "FLOAT"]), &[core::any::TypeId::of::(), core::any::TypeId::of::()], + m.set_fn("foo", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut FLOAT", "y: INT", "FLOAT"]), + &[core::any::TypeId::of::(), core::any::TypeId::of::()], foo_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] struct foo_token(); impl PluginFunction for foo_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 2usize, "wrong arg count: {} != {}", args.len(), 2usize); @@ -1261,33 +1215,27 @@ mod generate_tests { Ok(Dynamic::from(foo(arg0, arg1))) } - fn is_method_call(&self) -> bool { true } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { true } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(foo_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut FLOAT", "y: INT"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: &mut FLOAT", "y: INT", "FLOAT"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::(), TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "FLOAT" - } } - pub fn foo_token_callable() -> CallableFunction { + #[inline(always)] pub fn foo_token_callable() -> CallableFunction { foo_token().into() } - pub fn foo_token_input_names() -> Box<[&'static str]> { - foo_token().input_names() + #[inline(always)] pub fn foo_token_param_names() -> Box<[&'static str]> { + foo_token().param_names() } - pub fn foo_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn foo_token_input_types() -> Box<[TypeId]> { foo_token().input_types() } - pub fn foo_token_return_type() -> &'static str { - foo_token().return_type() - } } }; @@ -1321,14 +1269,15 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("increment", FnNamespace::Internal, FnAccess::Public, - Some(&["x: &mut FLOAT", "()"]), &[core::any::TypeId::of::()], + m.set_fn("increment", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut FLOAT", "()"]), + &[core::any::TypeId::of::()], increment_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] struct increment_token(); impl PluginFunction for increment_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 1usize, "wrong arg count: {} != {}", args.len(), 1usize); @@ -1341,33 +1290,27 @@ mod generate_tests { Ok(Dynamic::from(increment(arg0))) } - fn is_method_call(&self) -> bool { true } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { true } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(increment_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut FLOAT"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: &mut FLOAT", "()"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "()" - } } - pub fn increment_token_callable() -> CallableFunction { + #[inline(always)] pub fn increment_token_callable() -> CallableFunction { increment_token().into() } - pub fn increment_token_input_names() -> Box<[&'static str]> { - increment_token().input_names() + #[inline(always)] pub fn increment_token_param_names() -> Box<[&'static str]> { + increment_token().param_names() } - pub fn increment_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn increment_token_input_types() -> Box<[TypeId]> { increment_token().input_types() } - pub fn increment_token_return_type() -> &'static str { - increment_token().return_type() - } } }; @@ -1404,14 +1347,15 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("increment", FnNamespace::Internal, FnAccess::Public, - Some(&["x: &mut FLOAT", "()"]), &[core::any::TypeId::of::()], + m.set_fn("increment", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut FLOAT", "()"]), + &[core::any::TypeId::of::()], increment_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] struct increment_token(); impl PluginFunction for increment_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 1usize, "wrong arg count: {} != {}", args.len(), 1usize); @@ -1424,33 +1368,27 @@ mod generate_tests { Ok(Dynamic::from(increment(arg0))) } - fn is_method_call(&self) -> bool { true } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { true } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(increment_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut FLOAT"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: &mut FLOAT", "()"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "()" - } } - pub fn increment_token_callable() -> CallableFunction { + #[inline(always)] pub fn increment_token_callable() -> CallableFunction { increment_token().into() } - pub fn increment_token_input_names() -> Box<[&'static str]> { - increment_token().input_names() + #[inline(always)] pub fn increment_token_param_names() -> Box<[&'static str]> { + increment_token().param_names() } - pub fn increment_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn increment_token_input_types() -> Box<[TypeId]> { increment_token().input_types() } - pub fn increment_token_return_type() -> &'static str { - increment_token().return_type() - } } #[allow(unused_imports)] use super::*; @@ -1508,14 +1446,15 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("increment", FnNamespace::Internal, FnAccess::Public, - Some(&["x: &mut FLOAT", "()"]), &[core::any::TypeId::of::()], + m.set_fn("increment", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut FLOAT", "()"]), + &[core::any::TypeId::of::()], increment_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] struct increment_token(); impl PluginFunction for increment_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 1usize, "wrong arg count: {} != {}", args.len(), 1usize); @@ -1528,33 +1467,27 @@ mod generate_tests { Ok(Dynamic::from(increment(arg0))) } - fn is_method_call(&self) -> bool { true } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { true } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(increment_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut FLOAT"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: &mut FLOAT", "()"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "()" - } } - pub fn increment_token_callable() -> CallableFunction { + #[inline(always)] pub fn increment_token_callable() -> CallableFunction { increment_token().into() } - pub fn increment_token_input_names() -> Box<[&'static str]> { - increment_token().input_names() + #[inline(always)] pub fn increment_token_param_names() -> Box<[&'static str]> { + increment_token().param_names() } - pub fn increment_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn increment_token_input_types() -> Box<[TypeId]> { increment_token().input_types() } - pub fn increment_token_return_type() -> &'static str { - increment_token().return_type() - } } #[allow(unused_imports)] use super::*; @@ -1619,6 +1552,7 @@ mod generate_tests { #[allow(non_camel_case_types)] struct int_foo_token(); impl PluginFunction for int_foo_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 1usize, "wrong arg count: {} != {}", args.len(), 1usize); @@ -1631,33 +1565,27 @@ mod generate_tests { Ok(Dynamic::from(int_foo(arg0))) } - fn is_method_call(&self) -> bool { true } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { true } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(int_foo_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut u64"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: &mut u64", "u64"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "u64" - } } - pub fn int_foo_token_callable() -> CallableFunction { + #[inline(always)] pub fn int_foo_token_callable() -> CallableFunction { int_foo_token().into() } - pub fn int_foo_token_input_names() -> Box<[&'static str]> { - int_foo_token().input_names() + #[inline(always)] pub fn int_foo_token_param_names() -> Box<[&'static str]> { + int_foo_token().param_names() } - pub fn int_foo_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn int_foo_token_input_types() -> Box<[TypeId]> { int_foo_token().input_types() } - pub fn int_foo_token_return_type() -> &'static str { - int_foo_token().return_type() - } } }; @@ -1692,15 +1620,18 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("square", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut u64", "u64"]), &[core::any::TypeId::of::()], + m.set_fn("square", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut u64", "u64"]), + &[core::any::TypeId::of::()], int_foo_token().into()); - m.set_fn("get$square", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut u64", "u64"]), &[core::any::TypeId::of::()], + m.set_fn("get$square", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut u64", "u64"]), + &[core::any::TypeId::of::()], int_foo_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] struct int_foo_token(); impl PluginFunction for int_foo_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 1usize, "wrong arg count: {} != {}", args.len(), 1usize); @@ -1713,33 +1644,27 @@ mod generate_tests { Ok(Dynamic::from(int_foo(arg0))) } - fn is_method_call(&self) -> bool { true } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { true } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(int_foo_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut u64"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: &mut u64", "u64"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "u64" - } } - pub fn int_foo_token_callable() -> CallableFunction { + #[inline(always)] pub fn int_foo_token_callable() -> CallableFunction { int_foo_token().into() } - pub fn int_foo_token_input_names() -> Box<[&'static str]> { - int_foo_token().input_names() + #[inline(always)] pub fn int_foo_token_param_names() -> Box<[&'static str]> { + int_foo_token().param_names() } - pub fn int_foo_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn int_foo_token_input_types() -> Box<[TypeId]> { int_foo_token().input_types() } - pub fn int_foo_token_return_type() -> &'static str { - int_foo_token().return_type() - } } }; @@ -1782,6 +1707,7 @@ mod generate_tests { #[allow(non_camel_case_types)] struct int_foo_token(); impl PluginFunction for int_foo_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 2usize, "wrong arg count: {} != {}", args.len(), 2usize); @@ -1795,33 +1721,27 @@ mod generate_tests { Ok(Dynamic::from(int_foo(arg0, arg1))) } - fn is_method_call(&self) -> bool { true } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { true } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(int_foo_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut u64", "y: u64"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: &mut u64", "y: u64", "()"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::(), TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "()" - } } - pub fn int_foo_token_callable() -> CallableFunction { + #[inline(always)] pub fn int_foo_token_callable() -> CallableFunction { int_foo_token().into() } - pub fn int_foo_token_input_names() -> Box<[&'static str]> { - int_foo_token().input_names() + #[inline(always)] pub fn int_foo_token_param_names() -> Box<[&'static str]> { + int_foo_token().param_names() } - pub fn int_foo_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn int_foo_token_input_types() -> Box<[TypeId]> { int_foo_token().input_types() } - pub fn int_foo_token_return_type() -> &'static str { - int_foo_token().return_type() - } } }; @@ -1867,6 +1787,7 @@ mod generate_tests { #[allow(non_camel_case_types)] struct int_foo_token(); impl PluginFunction for int_foo_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 2usize, "wrong arg count: {} != {}", args.len(), 2usize); @@ -1880,33 +1801,27 @@ mod generate_tests { Ok(Dynamic::from(int_foo(arg0, arg1))) } - fn is_method_call(&self) -> bool { true } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { true } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(int_foo_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut u64", "y: u64"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: &mut u64", "y: u64", "()"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::(), TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "()" - } } - pub fn int_foo_token_callable() -> CallableFunction { + #[inline(always)] pub fn int_foo_token_callable() -> CallableFunction { int_foo_token().into() } - pub fn int_foo_token_input_names() -> Box<[&'static str]> { - int_foo_token().input_names() + #[inline(always)] pub fn int_foo_token_param_names() -> Box<[&'static str]> { + int_foo_token().param_names() } - pub fn int_foo_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn int_foo_token_input_types() -> Box<[TypeId]> { int_foo_token().input_types() } - pub fn int_foo_token_return_type() -> &'static str { - int_foo_token().return_type() - } } }; @@ -1941,16 +1856,15 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("index$get$", FnNamespace::Global, FnAccess::Public, - Some(&["x: &mut MyCollection", "i: u64", "FLOAT"]), - &[core::any::TypeId::of::(), - core::any::TypeId::of::()], + m.set_fn("index$get$", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut MyCollection", "i: u64", "FLOAT"]), + &[core::any::TypeId::of::(), core::any::TypeId::of::()], get_by_index_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] struct get_by_index_token(); impl PluginFunction for get_by_index_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 2usize, "wrong arg count: {} != {}", args.len(), 2usize); @@ -1964,34 +1878,28 @@ mod generate_tests { Ok(Dynamic::from(get_by_index(arg0, arg1))) } - fn is_method_call(&self) -> bool { true } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { true } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(get_by_index_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut MyCollection", "i: u64"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: &mut MyCollection", "i: u64", "FLOAT"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::(), TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "FLOAT" - } } - pub fn get_by_index_token_callable() -> CallableFunction { + #[inline(always)] pub fn get_by_index_token_callable() -> CallableFunction { get_by_index_token().into() } - pub fn get_by_index_token_input_names() -> Box<[&'static str]> { - get_by_index_token().input_names() + #[inline(always)] pub fn get_by_index_token_param_names() -> Box<[&'static str]> { + get_by_index_token().param_names() } - pub fn get_by_index_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn get_by_index_token_input_types() -> Box<[TypeId]> { get_by_index_token().input_types() } - pub fn get_by_index_token_return_type() -> &'static str { - get_by_index_token().return_type() - } } }; @@ -2026,21 +1934,18 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("get", FnNamespace::Internal, FnAccess::Public, - Some(&["x: &mut MyCollection", "i: u64", "FLOAT"]), - &[core::any::TypeId::of::(), - core::any::TypeId::of::()], + m.set_fn("get", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut MyCollection", "i: u64", "FLOAT"]), + &[core::any::TypeId::of::(), core::any::TypeId::of::()], get_by_index_token().into()); - m.set_fn("index$get$", FnNamespace::Global, FnAccess::Public, - Some(&["x: &mut MyCollection", "i: u64", "FLOAT"]), - &[core::any::TypeId::of::(), - core::any::TypeId::of::()], + m.set_fn("index$get$", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut MyCollection", "i: u64", "FLOAT"]), + &[core::any::TypeId::of::(), core::any::TypeId::of::()], get_by_index_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] struct get_by_index_token(); impl PluginFunction for get_by_index_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 2usize, "wrong arg count: {} != {}", args.len(), 2usize); @@ -2054,34 +1959,28 @@ mod generate_tests { Ok(Dynamic::from(get_by_index(arg0, arg1))) } - fn is_method_call(&self) -> bool { true } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { true } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(get_by_index_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut MyCollection", "i: u64"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: &mut MyCollection", "i: u64", "FLOAT"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::(), TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "FLOAT" - } } - pub fn get_by_index_token_callable() -> CallableFunction { + #[inline(always)] pub fn get_by_index_token_callable() -> CallableFunction { get_by_index_token().into() } - pub fn get_by_index_token_input_names() -> Box<[&'static str]> { - get_by_index_token().input_names() + #[inline(always)] pub fn get_by_index_token_param_names() -> Box<[&'static str]> { + get_by_index_token().param_names() } - pub fn get_by_index_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn get_by_index_token_input_types() -> Box<[TypeId]> { get_by_index_token().input_types() } - pub fn get_by_index_token_return_type() -> &'static str { - get_by_index_token().return_type() - } } }; @@ -2116,17 +2015,15 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("index$set$", FnNamespace::Global, FnAccess::Public, - Some(&["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"]), - &[core::any::TypeId::of::(), - core::any::TypeId::of::(), - core::any::TypeId::of::()], + m.set_fn("index$set$", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"]), + &[core::any::TypeId::of::(), core::any::TypeId::of::(), core::any::TypeId::of::()], set_by_index_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] struct set_by_index_token(); impl PluginFunction for set_by_index_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 3usize, "wrong arg count: {} != {}", args.len(), 3usize); @@ -2141,35 +2038,29 @@ mod generate_tests { Ok(Dynamic::from(set_by_index(arg0, arg1, arg2))) } - fn is_method_call(&self) -> bool { true } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { true } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(set_by_index_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut MyCollection", "i: u64", "item: FLOAT"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::(), TypeId::of::(), TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "()" - } } - pub fn set_by_index_token_callable() -> CallableFunction { + #[inline(always)] pub fn set_by_index_token_callable() -> CallableFunction { set_by_index_token().into() } - pub fn set_by_index_token_input_names() -> Box<[&'static str]> { - set_by_index_token().input_names() + #[inline(always)] pub fn set_by_index_token_param_names() -> Box<[&'static str]> { + set_by_index_token().param_names() } - pub fn set_by_index_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn set_by_index_token_input_types() -> Box<[TypeId]> { set_by_index_token().input_types() } - pub fn set_by_index_token_return_type() -> &'static str { - set_by_index_token().return_type() - } } }; @@ -2204,23 +2095,18 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("set", FnNamespace::Internal, FnAccess::Public, - Some(&["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"]), - &[core::any::TypeId::of::(), - core::any::TypeId::of::(), - core::any::TypeId::of::()], + m.set_fn("set", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"]), + &[core::any::TypeId::of::(), core::any::TypeId::of::(), core::any::TypeId::of::()], set_by_index_token().into()); - m.set_fn("index$set$", FnNamespace::Global, FnAccess::Public, - Some(&["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"]), - &[core::any::TypeId::of::(), - core::any::TypeId::of::(), - core::any::TypeId::of::()], + m.set_fn("index$set$", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"]), + &[core::any::TypeId::of::(), core::any::TypeId::of::(), core::any::TypeId::of::()], set_by_index_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] struct set_by_index_token(); impl PluginFunction for set_by_index_token { + #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { debug_assert_eq!(args.len(), 3usize, "wrong arg count: {} != {}", args.len(), 3usize); @@ -2235,35 +2121,29 @@ mod generate_tests { Ok(Dynamic::from(set_by_index(arg0, arg1, arg2))) } - fn is_method_call(&self) -> bool { true } - fn is_variadic(&self) -> bool { false } - fn clone_boxed(&self) -> Box { + #[inline(always)] fn is_method_call(&self) -> bool { true } + #[inline(always)] fn is_variadic(&self) -> bool { false } + #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(set_by_index_token()) } - fn input_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut MyCollection", "i: u64", "item: FLOAT"].into_boxed_slice() + #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { + new_vec!["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"].into_boxed_slice() } - fn input_types(&self) -> Box<[TypeId]> { + #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { new_vec![TypeId::of::(), TypeId::of::(), TypeId::of::()].into_boxed_slice() } - fn return_type(&self) -> &'static str { - "()" - } } - pub fn set_by_index_token_callable() -> CallableFunction { + #[inline(always)] pub fn set_by_index_token_callable() -> CallableFunction { set_by_index_token().into() } - pub fn set_by_index_token_input_names() -> Box<[&'static str]> { - set_by_index_token().input_names() + #[inline(always)] pub fn set_by_index_token_param_names() -> Box<[&'static str]> { + set_by_index_token().param_names() } - pub fn set_by_index_token_input_types() -> Box<[TypeId]> { + #[inline(always)] pub fn set_by_index_token_input_types() -> Box<[TypeId]> { set_by_index_token().input_types() } - pub fn set_by_index_token_return_type() -> &'static str { - set_by_index_token().return_type() - } } }; diff --git a/src/plugin.rs b/src/plugin.rs index d33aab73..4a890af6 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -30,12 +30,9 @@ pub trait PluginFunction { /// Convert a plugin function into a boxed trait object. fn clone_boxed(&self) -> Box; - /// Return a boxed slice of the names of the function's parameters. - fn input_names(&self) -> Box<[&'static str]>; + /// Return a boxed slice of the names of the function's parameters and return type. + fn param_names(&self) -> Box<[&'static str]>; /// Return a boxed slice of type ID's of the function's parameters. fn input_types(&self) -> Box<[TypeId]>; - - /// Return a string slice of the function's return type. - fn return_type(&self) -> &'static str; }