Use NonZeroU64/U32 for PadProbeId, NotifyId and DeviceMonitorFilterId

This allows for some further optimizations.
This commit is contained in:
Sebastian Dröge 2020-01-05 04:38:55 +02:00
parent c298577139
commit 8aac047af5
3 changed files with 15 additions and 11 deletions

View file

@ -15,6 +15,8 @@ use glib::translate::*;
use gst_sys;
use std::num::NonZeroU32;
impl DeviceMonitor {
pub fn new() -> DeviceMonitor {
assert_initialized_main_thread!();
@ -35,13 +37,13 @@ impl Default for DeviceMonitor {
}
#[derive(Debug, PartialEq, Eq)]
pub struct DeviceMonitorFilterId(libc::c_uint);
pub struct DeviceMonitorFilterId(NonZeroU32);
impl ToGlib for DeviceMonitorFilterId {
type GlibType = libc::c_uint;
fn to_glib(&self) -> libc::c_uint {
self.0
self.0.get()
}
}
@ -49,7 +51,7 @@ impl FromGlib<libc::c_uint> for DeviceMonitorFilterId {
fn from_glib(val: libc::c_uint) -> DeviceMonitorFilterId {
skip_assert_initialized!();
assert_ne!(val, 0);
DeviceMonitorFilterId(val)
DeviceMonitorFilterId(unsafe { NonZeroU32::new_unchecked(val) })
}
}

View file

@ -39,6 +39,7 @@ use StateChangeSuccess;
use std::ffi::CStr;
use std::mem;
use std::num::NonZeroU64;
use libc;
@ -106,13 +107,13 @@ pub enum ElementMessageType {
}
#[derive(Debug, PartialEq, Eq)]
pub struct NotifyWatchId(libc::c_ulong);
pub struct NotifyWatchId(NonZeroU64);
impl ToGlib for NotifyWatchId {
type GlibType = libc::c_ulong;
fn to_glib(&self) -> libc::c_ulong {
self.0
self.0.get() as libc::c_ulong
}
}
@ -120,7 +121,7 @@ impl FromGlib<libc::c_ulong> for NotifyWatchId {
fn from_glib(val: libc::c_ulong) -> NotifyWatchId {
skip_assert_initialized!();
assert_ne!(val, 0);
NotifyWatchId(val)
NotifyWatchId(unsafe { NonZeroU64::new_unchecked(val as u64) })
}
}
@ -569,7 +570,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
unsafe {
gst_sys::gst_element_remove_property_notify_watch(
self.as_ref().to_glib_none().0,
watch_id.0,
watch_id.to_glib(),
);
}
}

View file

@ -32,6 +32,7 @@ use StaticPadTemplate;
use std::cell::RefCell;
use std::mem;
use std::num::NonZeroU64;
use std::ptr;
use glib;
@ -61,13 +62,13 @@ impl Pad {
}
#[derive(Debug, PartialEq, Eq)]
pub struct PadProbeId(libc::c_ulong);
pub struct PadProbeId(NonZeroU64);
impl ToGlib for PadProbeId {
type GlibType = libc::c_ulong;
fn to_glib(&self) -> libc::c_ulong {
self.0
self.0.get() as libc::c_ulong
}
}
@ -75,7 +76,7 @@ impl FromGlib<libc::c_ulong> for PadProbeId {
fn from_glib(val: libc::c_ulong) -> PadProbeId {
skip_assert_initialized!();
assert_ne!(val, 0);
PadProbeId(val)
PadProbeId(unsafe { NonZeroU64::new_unchecked(val as u64) })
}
}
@ -1032,7 +1033,7 @@ where
let mut probe_info = PadProbeInfo {
mask: from_glib((*info).type_),
id: PadProbeId((*info).id),
id: PadProbeId(NonZeroU64::new_unchecked((*info).id)),
offset: (*info).offset,
size: (*info).size,
data: if (*info).data.is_null() {