summaryrefslogtreecommitdiff
path: root/ops/lib.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-08-28 12:21:49 +0530
committerGitHub <noreply@github.com>2022-08-28 12:21:49 +0530
commitd8396225c4287c53dd42226266e9f66983125e51 (patch)
tree27516437c40b80596f4d0fc9b821882a0f2a0ca1 /ops/lib.rs
parent7c4f57e8b091bc386242f83b5373e4bb33382012 (diff)
perf: use fast api for op_now (#15643)
Diffstat (limited to 'ops/lib.rs')
-rw-r--r--ops/lib.rs30
1 files changed, 21 insertions, 9 deletions
diff --git a/ops/lib.rs b/ops/lib.rs
index 2028fc875..500e1f5f9 100644
--- a/ops/lib.rs
+++ b/ops/lib.rs
@@ -365,15 +365,32 @@ fn codegen_fast_impl(
}
},
quote! {
- #func_name #ty_generics as *const _
+ #func_name::<#type_params> as *const _
},
)
};
+
+ let fast_struct = format_ident!("fast_{}", name);
+ let (type_params, ty_generics, struct_generics) =
+ if type_params.is_empty() {
+ (quote! { () }, quote! {}, quote! {})
+ } else {
+ (
+ quote! { #type_params },
+ quote! { #ty_generics },
+ quote! { ::<#type_params> },
+ )
+ };
return (
quote! {
+ #[allow(non_camel_case_types)]
+ #[doc(hidden)]
+ struct #fast_struct #ty_generics {
+ _phantom: ::std::marker::PhantomData<#type_params>,
+ }
#trampoline
- impl #impl_generics #core::v8::fast_api::FastFunction for #name #ty_generics {
- fn function(&self) -> *const ::std::ffi::c_void {
+ impl #impl_generics #core::v8::fast_api::FastFunction for #fast_struct #ty_generics #where_clause {
+ fn function(&self) -> *const ::std::ffi::c_void {
#raw_block
}
fn args(&self) -> &'static [#core::v8::fast_api::Type] {
@@ -384,7 +401,7 @@ fn codegen_fast_impl(
}
}
},
- quote! { Some(Box::new(#name #ty_generics)) },
+ quote! { Some(Box::new(#fast_struct #struct_generics { _phantom: ::std::marker::PhantomData })) },
);
}
}
@@ -439,11 +456,6 @@ struct FastApiSyn {
}
fn can_be_fast_api(core: &TokenStream2, f: &syn::ItemFn) -> Option<FastApiSyn> {
- // TODO(@littledivy): Support generics
- if !f.sig.generics.params.is_empty() {
- return None;
- }
-
let inputs = &f.sig.inputs;
let ret = match &f.sig.output {
syn::ReturnType::Default => quote!(#core::v8::fast_api::CType::Void),