Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit 26aa57c

Browse files
authored
Merge pull request #434 from sdroege/single-boxed-bytes
Only box data passed to Bytes::from_owned() once
2 parents cd7c8e0 + 6f59aec commit 26aa57c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/bytes.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ impl Bytes {
5353

5454
/// Takes ownership of `data` and creates a new `Bytes` without copying.
5555
pub fn from_owned<T: AsRef<[u8]> + Send + 'static>(data: T) -> Bytes {
56-
let data: Box<Box<AsRef<[u8]>>> = Box::new(Box::new(data));
56+
let data: Box<T> = Box::new(data);
5757
let (size, data_ptr) = {
58-
let data = (**data).as_ref();
58+
let data = (*data).as_ref();
5959
(data.len(), data.as_ptr())
6060
};
6161

62-
unsafe extern "C" fn drop_box(b: glib_ffi::gpointer) {
63-
let _: Box<Box<AsRef<[u8]>>> = Box::from_raw(b as *mut _);
62+
unsafe extern "C" fn drop_box<T: AsRef<[u8]> + Send + 'static>(b: glib_ffi::gpointer) {
63+
let _: Box<T> = Box::from_raw(b as *mut _);
6464
}
6565

6666
unsafe {
67-
from_glib_full(glib_ffi::g_bytes_new_with_free_func(data_ptr as *const _, size, Some(drop_box), Box::into_raw(data) as *mut _))
67+
from_glib_full(glib_ffi::g_bytes_new_with_free_func(data_ptr as *const _, size, Some(drop_box::<T>), Box::into_raw(data) as *mut _))
6868
}
6969
}
7070
}

0 commit comments

Comments
 (0)