Use PhantomData as Stash::Storage if nothing has to be stored except for a lifetime

This reduces the size of all stashes from two pointers to one.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1171>
This commit is contained in:
Sebastian Dröge 2022-12-17 18:48:35 +02:00 committed by GStreamer Marge Bot
parent f166e80a79
commit d6cc452cf3
20 changed files with 78 additions and 62 deletions

View file

@ -3,6 +3,7 @@
use std::cmp::Ordering;
use std::ffi::CStr;
use std::fmt;
use std::marker::PhantomData;
use std::str;
use glib::translate::{from_glib, from_glib_none, FromGlib, IntoGlib, ToGlibPtr, ToGlibPtrMut};
@ -380,10 +381,10 @@ impl glib::translate::GlibPtrDefault for AudioFormatInfo {
#[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstAudioFormatInfo> for AudioFormatInfo {
type Storage = &'a Self;
type Storage = PhantomData<&'a Self>;
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstAudioFormatInfo, Self> {
glib::translate::Stash(self.0, self)
glib::translate::Stash(self.0, PhantomData)
}
fn to_glib_full(&self) -> *const ffi::GstAudioFormatInfo {

View file

@ -6,6 +6,7 @@ use glib::translate::{
use gst::prelude::*;
use std::fmt;
use std::marker::PhantomData;
use std::mem;
use std::ptr;
@ -398,10 +399,10 @@ impl glib::translate::GlibPtrDefault for AudioInfo {
#[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstAudioInfo> for AudioInfo {
type Storage = &'a Self;
type Storage = PhantomData<&'a Self>;
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstAudioInfo, Self> {
glib::translate::Stash(&self.0, self)
glib::translate::Stash(&self.0, PhantomData)
}
fn to_glib_full(&self) -> *const ffi::GstAudioInfo {

View file

@ -51,10 +51,10 @@ impl FromGlib<i32> for Overhead {
#[doc(hidden)]
impl<'a> ::glib::translate::ToGlibPtr<'a, *mut ffi::GstBaseParseFrame> for BaseParseFrame<'a> {
type Storage = &'a Self;
type Storage = PhantomData<&'a Self>;
fn to_glib_none(&'a self) -> ::glib::translate::Stash<*mut ffi::GstBaseParseFrame, Self> {
Stash(self.0.as_ptr(), self)
Stash(self.0.as_ptr(), PhantomData)
}
fn to_glib_full(&self) -> *mut ffi::GstBaseParseFrame {

View file

@ -1,6 +1,7 @@
// Take a look at the license at the top of the repository in the LICENSE file.
use glib::translate::*;
use std::marker::PhantomData;
use std::ptr;
#[derive(Debug, PartialEq, Eq)]
@ -34,10 +35,10 @@ impl FromGlibPtrBorrow<*mut ffi::GstRTSPContext> for RTSPContext {
#[doc(hidden)]
impl<'a> ToGlibPtr<'a, *mut ffi::GstRTSPContext> for RTSPContext {
type Storage = &'a RTSPContext;
type Storage = PhantomData<&'a RTSPContext>;
fn to_glib_none(&'a self) -> Stash<'a, *mut ffi::GstRTSPContext, Self> {
Stash(self.0.as_ptr(), self)
Stash(self.0.as_ptr(), PhantomData)
}
fn to_glib_full(&self) -> *mut ffi::GstRTSPContext {

View file

@ -1,6 +1,7 @@
// Take a look at the license at the top of the repository in the LICENSE file.
use std::ffi::CStr;
use std::marker::PhantomData;
use std::mem;
use glib::translate::*;
@ -91,10 +92,10 @@ impl Eq for VideoAlignment {}
#[doc(hidden)]
impl<'a> ToGlibPtr<'a, *const ffi::GstVideoAlignment> for VideoAlignment {
type Storage = &'a Self;
type Storage = PhantomData<&'a Self>;
fn to_glib_none(&'a self) -> Stash<*const ffi::GstVideoAlignment, Self> {
Stash(&self.0, self)
Stash(&self.0, PhantomData)
}
}

View file

@ -4,6 +4,7 @@ use crate::utils::HasStreamLock;
use crate::VideoCodecFrameFlags;
use glib::translate::*;
use std::fmt;
use std::marker::PhantomData;
use std::mem;
pub struct VideoCodecFrame<'a> {
@ -15,10 +16,10 @@ pub struct VideoCodecFrame<'a> {
#[doc(hidden)]
impl<'a> ::glib::translate::ToGlibPtr<'a, *mut ffi::GstVideoCodecFrame> for VideoCodecFrame<'a> {
type Storage = &'a Self;
type Storage = PhantomData<&'a Self>;
fn to_glib_none(&'a self) -> ::glib::translate::Stash<'a, *mut ffi::GstVideoCodecFrame, Self> {
Stash(self.frame, self)
Stash(self.frame, PhantomData)
}
fn to_glib_full(&self) -> *mut ffi::GstVideoCodecFrame {

View file

@ -3,6 +3,7 @@
use std::cmp::Ordering;
use std::ffi::CStr;
use std::fmt;
use std::marker::PhantomData;
use std::str;
use glib::translate::{from_glib, IntoGlib, ToGlibPtr};
@ -513,10 +514,10 @@ impl glib::translate::GlibPtrDefault for VideoFormatInfo {
#[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstVideoFormatInfo> for VideoFormatInfo {
type Storage = &'a Self;
type Storage = PhantomData<&'a Self>;
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstVideoFormatInfo, Self> {
glib::translate::Stash(self.0, self)
glib::translate::Stash(self.0, PhantomData)
}
fn to_glib_full(&self) -> *const ffi::GstVideoFormatInfo {

View file

@ -4,6 +4,7 @@ use glib::translate::*;
use gst::prelude::*;
use std::fmt;
use std::marker::PhantomData;
use std::mem;
use std::ptr;
use std::str;
@ -921,10 +922,10 @@ impl glib::translate::GlibPtrDefault for VideoInfo {
#[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstVideoInfo> for VideoInfo {
type Storage = &'a Self;
type Storage = PhantomData<&'a Self>;
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstVideoInfo, Self> {
glib::translate::Stash(&self.0, self)
glib::translate::Stash(&self.0, PhantomData)
}
fn to_glib_full(&self) -> *const ffi::GstVideoInfo {

View file

@ -1,6 +1,7 @@
// Take a look at the license at the top of the repository in the LICENSE file.
use glib::translate::IntoGlib;
use std::marker::PhantomData;
use std::mem;
#[repr(C)]
@ -58,11 +59,11 @@ impl glib::translate::Uninitialized for VideoRectangle {
#[doc(hidden)]
impl<'a> glib::translate::ToGlibPtrMut<'a, *mut ffi::GstVideoRectangle> for VideoRectangle {
type Storage = &'a mut Self;
type Storage = PhantomData<&'a mut Self>;
fn to_glib_none_mut(
&'a mut self,
) -> glib::translate::StashMut<*mut ffi::GstVideoRectangle, Self> {
glib::translate::StashMut(self as *mut _ as *mut _, self)
glib::translate::StashMut(self as *mut _ as *mut _, PhantomData)
}
}

View file

@ -4,6 +4,7 @@ use glib::translate::*;
use gst::prelude::*;
use std::cmp;
use std::fmt;
use std::marker::PhantomData;
use std::mem;
use std::ptr;
use std::str;
@ -352,11 +353,11 @@ macro_rules! generic_impl {
#[doc(hidden)]
impl<'a> ToGlibPtr<'a, *const ffi::GstVideoTimeCode> for $name {
type Storage = &'a Self;
type Storage = PhantomData<&'a Self>;
#[inline]
fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstVideoTimeCode, Self> {
Stash(&self.0 as *const _, self)
Stash(&self.0 as *const _, PhantomData)
}
#[inline]
@ -367,12 +368,12 @@ macro_rules! generic_impl {
#[doc(hidden)]
impl<'a> ToGlibPtrMut<'a, *mut ffi::GstVideoTimeCode> for $name {
type Storage = &'a mut Self;
type Storage = PhantomData<&'a mut Self>;
#[inline]
fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut ffi::GstVideoTimeCode, Self> {
let ptr = &mut self.0 as *mut _;
StashMut(ptr, self)
StashMut(ptr, PhantomData)
}
}

View file

@ -4,6 +4,7 @@ use glib::prelude::*;
use glib::translate::*;
use std::cmp;
use std::fmt;
use std::marker::PhantomData;
use std::mem;
use std::ptr;
use std::str;
@ -137,11 +138,11 @@ impl GlibPtrDefault for VideoTimeCodeInterval {
#[doc(hidden)]
impl<'a> ToGlibPtr<'a, *const ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterval {
type Storage = &'a Self;
type Storage = PhantomData<&'a Self>;
#[inline]
fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstVideoTimeCodeInterval, Self> {
Stash(&self.0 as *const _, self)
Stash(&self.0 as *const _, PhantomData)
}
#[inline]
@ -152,12 +153,12 @@ impl<'a> ToGlibPtr<'a, *const ffi::GstVideoTimeCodeInterval> for VideoTimeCodeIn
#[doc(hidden)]
impl<'a> ToGlibPtrMut<'a, *mut ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterval {
type Storage = &'a mut Self;
type Storage = PhantomData<&'a mut Self>;
#[inline]
fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut ffi::GstVideoTimeCodeInterval, Self> {
let ptr = &mut self.0 as *mut _;
StashMut(ptr, self)
StashMut(ptr, PhantomData)
}
}

View file

@ -1,5 +1,6 @@
// Take a look at the license at the top of the repository in the LICENSE file.
use std::marker::PhantomData;
use std::mem;
use glib::translate::*;
@ -64,10 +65,10 @@ impl From<ffi::GstAllocationParams> for AllocationParams {
#[doc(hidden)]
impl<'a> ToGlibPtr<'a, *const ffi::GstAllocationParams> for AllocationParams {
type Storage = &'a Self;
type Storage = PhantomData<&'a Self>;
fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstAllocationParams, Self> {
Stash(&self.0, self)
Stash(&self.0, PhantomData)
}
}

View file

@ -9,6 +9,7 @@ use crate::StructureRef;
use glib::prelude::*;
use glib::translate::*;
use std::marker::PhantomData;
use std::mem;
use std::ops;
use std::ops::Deref;
@ -306,23 +307,23 @@ impl Eq for BufferPoolAcquireParams {}
#[doc(hidden)]
impl<'a> ToGlibPtr<'a, *const ffi::GstBufferPoolAcquireParams> for BufferPoolAcquireParams {
type Storage = &'a Self;
type Storage = PhantomData<&'a Self>;
fn to_glib_none(
&'a self,
) -> glib::translate::Stash<'a, *const ffi::GstBufferPoolAcquireParams, Self> {
glib::translate::Stash(&self.0, self)
glib::translate::Stash(&self.0, PhantomData)
}
}
#[doc(hidden)]
impl<'a> ToGlibPtrMut<'a, *mut ffi::GstBufferPoolAcquireParams> for BufferPoolAcquireParams {
type Storage = &'a mut Self;
type Storage = PhantomData<&'a mut Self>;
fn to_glib_none_mut(
&'a mut self,
) -> glib::translate::StashMut<'a, *mut ffi::GstBufferPoolAcquireParams, Self> {
glib::translate::StashMut(&mut self.0, self)
glib::translate::StashMut(&mut self.0, PhantomData)
}
}

View file

@ -3,6 +3,7 @@
use std::borrow::{Borrow, BorrowMut, ToOwned};
use std::ffi::CStr;
use std::fmt;
use std::marker::PhantomData;
use std::mem;
use std::ops::{Deref, DerefMut};
use std::ptr;
@ -164,10 +165,10 @@ impl glib::types::StaticType for CapsFeatures {
}
impl<'a> ToGlibPtr<'a, *const ffi::GstCapsFeatures> for CapsFeatures {
type Storage = &'a Self;
type Storage = PhantomData<&'a Self>;
fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstCapsFeatures, Self> {
unsafe { Stash(self.0.as_ref(), self) }
unsafe { Stash(self.0.as_ref(), PhantomData) }
}
fn to_glib_full(&self) -> *const ffi::GstCapsFeatures {
@ -176,13 +177,13 @@ impl<'a> ToGlibPtr<'a, *const ffi::GstCapsFeatures> for CapsFeatures {
}
impl<'a> ToGlibPtr<'a, *mut ffi::GstCapsFeatures> for CapsFeatures {
type Storage = &'a Self;
type Storage = PhantomData<&'a Self>;
fn to_glib_none(&'a self) -> Stash<'a, *mut ffi::GstCapsFeatures, Self> {
unsafe {
Stash(
self.0.as_ref() as *const ffi::GstCapsFeatures as *mut ffi::GstCapsFeatures,
self,
PhantomData,
)
}
}
@ -193,10 +194,10 @@ impl<'a> ToGlibPtr<'a, *mut ffi::GstCapsFeatures> for CapsFeatures {
}
impl<'a> ToGlibPtrMut<'a, *mut ffi::GstCapsFeatures> for CapsFeatures {
type Storage = &'a mut Self;
type Storage = PhantomData<&'a mut Self>;
fn to_glib_none_mut(&'a mut self) -> StashMut<*mut ffi::GstCapsFeatures, Self> {
unsafe { StashMut(self.0.as_mut(), self) }
unsafe { StashMut(self.0.as_mut(), PhantomData) }
}
}

View file

@ -570,10 +570,10 @@ impl<T> glib::translate::GlibPtrDefault for Iterator<T> {
#[doc(hidden)]
impl<'a, T: 'static> glib::translate::ToGlibPtr<'a, *const ffi::GstIterator> for Iterator<T> {
type Storage = &'a Iterator<T>;
type Storage = PhantomData<&'a Iterator<T>>;
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstIterator, Self> {
glib::translate::Stash(self.iter.as_ptr(), self)
glib::translate::Stash(self.iter.as_ptr(), PhantomData)
}
fn to_glib_full(&self) -> *const ffi::GstIterator {
@ -583,13 +583,13 @@ impl<'a, T: 'static> glib::translate::ToGlibPtr<'a, *const ffi::GstIterator> for
#[doc(hidden)]
impl<'a, T: 'static> glib::translate::ToGlibPtrMut<'a, *mut ffi::GstIterator> for Iterator<T> {
type Storage = &'a mut Iterator<T>;
type Storage = PhantomData<&'a mut Iterator<T>>;
#[inline]
fn to_glib_none_mut(
&'a mut self,
) -> glib::translate::StashMut<'a, *mut ffi::GstIterator, Self> {
glib::translate::StashMut(self.iter.as_ptr(), self)
glib::translate::StashMut(self.iter.as_ptr(), PhantomData)
}
}

View file

@ -146,10 +146,10 @@ macro_rules! mini_object_wrapper (
}
impl<'a> $crate::glib::translate::ToGlibPtr<'a, *const $ffi_name> for $name {
type Storage = &'a Self;
type Storage = std::marker::PhantomData<&'a Self>;
fn to_glib_none(&'a self) -> $crate::glib::translate::Stash<'a, *const $ffi_name, Self> {
$crate::glib::translate::Stash( self.as_ptr() , self)
$crate::glib::translate::Stash(self.as_ptr(), std::marker::PhantomData)
}
fn to_glib_full(&self) -> *const $ffi_name {
@ -161,10 +161,10 @@ macro_rules! mini_object_wrapper (
}
impl<'a> $crate::glib::translate::ToGlibPtr<'a, *mut $ffi_name> for $name {
type Storage = &'a Self;
type Storage = std::marker::PhantomData<&'a Self>;
fn to_glib_none(&'a self) -> $crate::glib::translate::Stash<'a, *mut $ffi_name, Self> {
$crate::glib::translate::Stash( self.as_mut_ptr() , self)
$crate::glib::translate::Stash(self.as_mut_ptr(), std::marker::PhantomData)
}
fn to_glib_full(&self) -> *mut $ffi_name {
@ -176,11 +176,11 @@ macro_rules! mini_object_wrapper (
}
impl<'a> $crate::glib::translate::ToGlibPtrMut<'a, *mut $ffi_name> for $name {
type Storage = &'a mut Self;
type Storage = std::marker::PhantomData<&'a mut Self>;
fn to_glib_none_mut(&'a mut self) -> $crate::glib::translate::StashMut<*mut $ffi_name, Self> {
self.make_mut();
$crate::glib::translate::StashMut( self.as_mut_ptr() , self)
$crate::glib::translate::StashMut(self.as_mut_ptr(), std::marker::PhantomData)
}
}

View file

@ -660,10 +660,10 @@ impl<T: FormattedValueIntrinsic> glib::translate::GlibPtrDefault for FormattedSe
impl<'a, T: FormattedValueIntrinsic> glib::translate::ToGlibPtr<'a, *const ffi::GstSegment>
for FormattedSegment<T>
{
type Storage = &'a FormattedSegment<T>;
type Storage = PhantomData<&'a FormattedSegment<T>>;
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstSegment, Self> {
glib::translate::Stash(&self.0, self)
glib::translate::Stash(&self.0, PhantomData)
}
fn to_glib_full(&self) -> *const ffi::GstSegment {
@ -675,11 +675,11 @@ impl<'a, T: FormattedValueIntrinsic> glib::translate::ToGlibPtr<'a, *const ffi::
impl<'a, T: FormattedValueIntrinsic> glib::translate::ToGlibPtrMut<'a, *mut ffi::GstSegment>
for FormattedSegment<T>
{
type Storage = &'a mut FormattedSegment<T>;
type Storage = PhantomData<&'a mut FormattedSegment<T>>;
#[inline]
fn to_glib_none_mut(&'a mut self) -> glib::translate::StashMut<'a, *mut ffi::GstSegment, Self> {
glib::translate::StashMut(&mut self.0, self)
glib::translate::StashMut(&mut self.0, PhantomData)
}
}

View file

@ -7,6 +7,7 @@ use glib::StaticType;
use std::ffi::CStr;
use std::fmt;
use std::marker::PhantomData;
use std::ptr;
#[doc(alias = "GstStaticCaps")]
@ -101,10 +102,10 @@ impl glib::translate::GlibPtrDefault for StaticCaps {
#[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticCaps> for StaticCaps {
type Storage = &'a StaticCaps;
type Storage = PhantomData<&'a StaticCaps>;
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstStaticCaps, Self> {
glib::translate::Stash(self.0.as_ptr(), self)
glib::translate::Stash(self.0.as_ptr(), PhantomData)
}
fn to_glib_full(&self) -> *const ffi::GstStaticCaps {

View file

@ -8,6 +8,7 @@ use glib::StaticType;
use std::ffi::CStr;
use std::fmt;
use std::marker::PhantomData;
use std::ptr;
#[doc(alias = "GstStaticPadTemplate")]
@ -132,12 +133,12 @@ impl glib::translate::GlibPtrDefault for StaticPadTemplate {
#[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticPadTemplate> for StaticPadTemplate {
type Storage = &'a StaticPadTemplate;
type Storage = PhantomData<&'a StaticPadTemplate>;
fn to_glib_none(
&'a self,
) -> glib::translate::Stash<'a, *const ffi::GstStaticPadTemplate, Self> {
glib::translate::Stash(self.0.as_ptr(), self)
glib::translate::Stash(self.0.as_ptr(), PhantomData)
}
fn to_glib_full(&self) -> *const ffi::GstStaticPadTemplate {

View file

@ -3,6 +3,7 @@
use std::borrow::{Borrow, BorrowMut, ToOwned};
use std::ffi::CStr;
use std::fmt;
use std::marker::PhantomData;
use std::mem;
use std::ops::{Deref, DerefMut};
use std::ptr;
@ -219,10 +220,10 @@ impl glib::types::StaticType for Structure {
}
impl<'a> ToGlibPtr<'a, *const ffi::GstStructure> for Structure {
type Storage = &'a Self;
type Storage = PhantomData<&'a Self>;
fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstStructure, Self> {
unsafe { Stash(self.0.as_ref(), self) }
unsafe { Stash(self.0.as_ref(), PhantomData) }
}
fn to_glib_full(&self) -> *const ffi::GstStructure {
@ -231,13 +232,13 @@ impl<'a> ToGlibPtr<'a, *const ffi::GstStructure> for Structure {
}
impl<'a> ToGlibPtr<'a, *mut ffi::GstStructure> for Structure {
type Storage = &'a Self;
type Storage = PhantomData<&'a Self>;
fn to_glib_none(&'a self) -> Stash<'a, *mut ffi::GstStructure, Self> {
unsafe {
Stash(
self.0.as_ref() as *const ffi::GstStructure as *mut ffi::GstStructure,
self,
PhantomData,
)
}
}
@ -248,10 +249,10 @@ impl<'a> ToGlibPtr<'a, *mut ffi::GstStructure> for Structure {
}
impl<'a> ToGlibPtrMut<'a, *mut ffi::GstStructure> for Structure {
type Storage = &'a mut Self;
type Storage = PhantomData<&'a mut Self>;
fn to_glib_none_mut(&'a mut self) -> StashMut<*mut ffi::GstStructure, Self> {
unsafe { StashMut(self.0.as_mut(), self) }
unsafe { StashMut(self.0.as_mut(), PhantomData) }
}
}