summaryrefslogtreecommitdiff
path: root/ext/ffi
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-03-31 18:12:14 +0530
committerGitHub <noreply@github.com>2023-03-31 14:42:14 +0200
commitb9a379093264da47368ea9665f685016fe35bfca (patch)
treeaf6fd2e56846b8d0a6d1d8d88c0bfcffbb34c4d6 /ext/ffi
parent0f41aff1d9f6c131ff69d6dd1dc053afb008a19d (diff)
perf: `const` op declaration (#18288)
Co-authored-by: Levente Kurusa <lkurusa@kernelstuff.org> Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'ext/ffi')
-rw-r--r--ext/ffi/turbocall.rs41
1 files changed, 12 insertions, 29 deletions
diff --git a/ext/ffi/turbocall.rs b/ext/ffi/turbocall.rs
index 3d01f00f5..f25f9274f 100644
--- a/ext/ffi/turbocall.rs
+++ b/ext/ffi/turbocall.rs
@@ -40,26 +40,29 @@ pub(crate) fn compile_trampoline(sym: &Symbol) -> Trampoline {
}
}
-pub(crate) fn make_template(sym: &Symbol, trampoline: &Trampoline) -> Template {
+pub(crate) fn make_template(
+ sym: &Symbol,
+ trampoline: &Trampoline,
+) -> fast_api::FastFunction {
let mut params = once(fast_api::Type::V8Value) // Receiver
.chain(sym.parameter_types.iter().map(|t| t.into()))
.collect::<Vec<_>>();
let ret = if needs_unwrap(&sym.result_type) {
params.push(fast_api::Type::TypedArray(fast_api::CType::Int32));
- fast_api::Type::Void
+ fast_api::CType::Void
} else if sym.result_type == NativeType::Buffer {
// Buffer can be used as a return type and converts differently than in parameters.
- fast_api::Type::Pointer
+ fast_api::CType::Pointer
} else {
- fast_api::Type::from(&sym.result_type)
+ fast_api::CType::from(&fast_api::Type::from(&sym.result_type))
};
- Template {
- args: params.into_boxed_slice(),
- ret: (&ret).into(),
- symbol_ptr: trampoline.ptr(),
- }
+ fast_api::FastFunction::new(
+ Box::leak(params.into_boxed_slice()),
+ ret,
+ trampoline.ptr(),
+ )
}
/// Trampoline for fast-call FFI functions
@@ -73,26 +76,6 @@ impl Trampoline {
}
}
-pub(crate) struct Template {
- pub args: Box<[fast_api::Type]>,
- pub ret: fast_api::CType,
- pub symbol_ptr: *const c_void,
-}
-
-impl fast_api::FastFunction for Template {
- fn function(&self) -> *const c_void {
- self.symbol_ptr
- }
-
- fn args(&self) -> &'static [fast_api::Type] {
- Box::leak(self.args.clone())
- }
-
- fn return_type(&self) -> fast_api::CType {
- self.ret
- }
-}
-
impl From<&NativeType> for fast_api::Type {
fn from(native_type: &NativeType) -> Self {
match native_type {