mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2025-04-27 07:24:53 +00:00
gstreamer: Only use a single temporary Vec
for [T]::to_glib_none()
for miniobjects
The value itself is already kept alive via the stash and we only need a temporary `Vec` to be able to append the terminating `NULL` pointer. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1171>
This commit is contained in:
parent
e70536f6b2
commit
f166e80a79
1 changed files with 9 additions and 10 deletions
|
@ -187,35 +187,34 @@ macro_rules! mini_object_wrapper (
|
||||||
impl<'a> $crate::glib::translate::ToGlibContainerFromSlice<'a, *mut *mut $ffi_name> for $name {
|
impl<'a> $crate::glib::translate::ToGlibContainerFromSlice<'a, *mut *mut $ffi_name> for $name {
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
type Storage = (
|
type Storage = (
|
||||||
Vec<$crate::glib::translate::Stash<'a, *mut $ffi_name, Self>>,
|
std::marker::PhantomData<&'a [$name]>,
|
||||||
Option<Vec<*mut $ffi_name>>,
|
Option<Vec<*mut $ffi_name>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn to_glib_none_from_slice(t: &'a [$name]) -> (*mut *mut $ffi_name, Self::Storage) {
|
fn to_glib_none_from_slice(t: &'a [$name]) -> (*mut *mut $ffi_name, Self::Storage) {
|
||||||
skip_assert_initialized!();
|
skip_assert_initialized!();
|
||||||
let v: Vec<_> = t.iter().map(|s| $crate::glib::translate::ToGlibPtr::to_glib_none(s)).collect();
|
let mut v_ptr = Vec::with_capacity(t.len() + 1);
|
||||||
let mut v_ptr: Vec<_> = v.iter().map(|s| s.0).collect();
|
v_ptr.extend(t.iter().map(|t| t.as_mut_ptr()));
|
||||||
v_ptr.push(std::ptr::null_mut() as *mut $ffi_name);
|
v_ptr.push(std::ptr::null_mut());
|
||||||
|
|
||||||
(v_ptr.as_ptr() as *mut *mut $ffi_name, (v, Some(v_ptr)))
|
(v_ptr.as_ptr() as *mut *mut $ffi_name, (std::marker::PhantomData, Some(v_ptr)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_glib_container_from_slice(t: &'a [$name]) -> (*mut *mut $ffi_name, Self::Storage) {
|
fn to_glib_container_from_slice(t: &'a [$name]) -> (*mut *mut $ffi_name, Self::Storage) {
|
||||||
skip_assert_initialized!();
|
skip_assert_initialized!();
|
||||||
let v: Vec<_> = t.iter().map(|s| $crate::glib::translate::ToGlibPtr::to_glib_none(s)).collect();
|
|
||||||
|
|
||||||
let v_ptr = unsafe {
|
let v_ptr = unsafe {
|
||||||
let v_ptr = $crate::glib::ffi::g_malloc0(std::mem::size_of::<*mut $ffi_name>() * t.len() + 1)
|
let v_ptr = $crate::glib::ffi::g_malloc0(std::mem::size_of::<*mut $ffi_name>() * t.len() + 1)
|
||||||
as *mut *mut $ffi_name;
|
as *mut *mut $ffi_name;
|
||||||
|
|
||||||
for (i, s) in v.iter().enumerate() {
|
for (i, t) in t.iter().enumerate() {
|
||||||
std::ptr::write(v_ptr.add(i), s.0);
|
std::ptr::write(v_ptr.add(i), t.as_mut_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
v_ptr
|
v_ptr
|
||||||
};
|
};
|
||||||
|
|
||||||
(v_ptr, (v, None))
|
(v_ptr, (std::marker::PhantomData, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_glib_full_from_slice(t: &[$name]) -> *mut *mut $ffi_name {
|
fn to_glib_full_from_slice(t: &[$name]) -> *mut *mut $ffi_name {
|
||||||
|
@ -238,7 +237,7 @@ macro_rules! mini_object_wrapper (
|
||||||
{
|
{
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
type Storage = (
|
type Storage = (
|
||||||
Vec<$crate::glib::translate::Stash<'a, *mut $ffi_name, $name>>,
|
std::marker::PhantomData<&'a [$name]>,
|
||||||
Option<Vec<*mut $ffi_name>>,
|
Option<Vec<*mut $ffi_name>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue