Skip to content

Commit 3a1118b

Browse files
committed
glib: Optimize [Type]::to_glib_none() to not have an additional heap allocation
1 parent f65029b commit 3a1118b

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

glib/src/types.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// rustdoc-stripper-ignore-next
44
//! Runtime type information.
55
6-
use std::{fmt, mem, ptr};
6+
use std::{fmt, marker::PhantomData, mem, ptr};
77

88
use crate::{translate::*, Slice};
99

@@ -508,16 +508,14 @@ impl IntoGlib for Type {
508508
}
509509

510510
impl<'a> ToGlibContainerFromSlice<'a, *mut ffi::GType> for Type {
511-
type Storage = Option<Vec<ffi::GType>>;
511+
type Storage = PhantomData<&'a [Type]>;
512512

513513
fn to_glib_none_from_slice(t: &'a [Type]) -> (*mut ffi::GType, Self::Storage) {
514-
let mut vec = t.iter().map(|t| t.into_glib()).collect::<Vec<_>>();
515-
516-
(vec.as_mut_ptr(), Some(vec))
514+
(t.as_ptr() as *mut ffi::GType, PhantomData)
517515
}
518516

519517
fn to_glib_container_from_slice(t: &'a [Type]) -> (*mut ffi::GType, Self::Storage) {
520-
(Self::to_glib_full_from_slice(t), None)
518+
(Self::to_glib_full_from_slice(t), PhantomData)
521519
}
522520

523521
fn to_glib_full_from_slice(t: &[Type]) -> *mut ffi::GType {

0 commit comments

Comments
 (0)