summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/isolate.rs21
-rw-r--r--src/libdeno.rs12
2 files changed, 15 insertions, 18 deletions
diff --git a/src/isolate.rs b/src/isolate.rs
index 6e4c421c7..a9088e708 100644
--- a/src/isolate.rs
+++ b/src/isolate.rs
@@ -190,15 +190,14 @@ impl Isolate {
pub fn respond(&mut self, req_id: i32, buf: Buf) {
self.state.metrics_op_completed(buf.len());
-
- // TODO(zero-copy) Use Buf::leak(buf) to leak the heap allocated buf. And
- // don't do the memcpy in ImportBuf() (in libdeno/binding.cc)
+ // deno_respond will memcpy the buf into V8's heap,
+ // so borrowing a reference here is sufficient.
unsafe {
libdeno::deno_respond(
self.libdeno_isolate,
self.as_void_ptr(),
req_id,
- buf.into(),
+ buf.as_ref().into(),
)
}
}
@@ -271,20 +270,6 @@ impl Drop for Isolate {
}
}
-/// Converts Rust Buf to libdeno `deno_buf`.
-impl From<Buf> for libdeno::deno_buf {
- fn from(x: Buf) -> Self {
- let len = x.len();
- let ptr = Box::into_raw(x);
- Self {
- alloc_ptr: std::ptr::null_mut(),
- alloc_len: 0,
- data_ptr: ptr as *mut u8,
- data_len: len,
- }
- }
-}
-
// Dereferences the C pointer into the Rust Isolate object.
extern "C" fn pre_dispatch(
user_data: *mut c_void,
diff --git a/src/libdeno.rs b/src/libdeno.rs
index c831dc73a..35278a7da 100644
--- a/src/libdeno.rs
+++ b/src/libdeno.rs
@@ -29,6 +29,18 @@ impl deno_buf {
}
}
+/// Converts Rust &Buf to libdeno `deno_buf`.
+impl<'a> From<&'a [u8]> for deno_buf {
+ fn from(x: &'a [u8]) -> Self {
+ Self {
+ alloc_ptr: std::ptr::null_mut(),
+ alloc_len: 0,
+ data_ptr: x.as_ref().as_ptr() as *mut u8,
+ data_len: x.len(),
+ }
+ }
+}
+
type DenoRecvCb = unsafe extern "C" fn(
user_data: *mut c_void,
req_id: i32,