diff --git a/src/gallium/frontends/rusticl/api/util.rs b/src/gallium/frontends/rusticl/api/util.rs index 200e03008e3..a490df7ed3a 100644 --- a/src/gallium/frontends/rusticl/api/util.rs +++ b/src/gallium/frontends/rusticl/api/util.rs @@ -404,7 +404,7 @@ where fn count(&self) -> usize { // Properties are value pairs terminated with a 0 value. - self.props.len() * 2 + 1 + self.len() * 2 + 1 } fn write_to(&self, out: &mut [MaybeUninit]) { @@ -414,7 +414,7 @@ where } // need to terminate with a 0 value - out[self.props.len() * 2].write(T::default()); + out[self.len() * 2].write(T::default()); } } diff --git a/src/gallium/frontends/rusticl/util/properties.rs b/src/gallium/frontends/rusticl/util/properties.rs index aad44e5098a..044eb77872a 100644 --- a/src/gallium/frontends/rusticl/util/properties.rs +++ b/src/gallium/frontends/rusticl/util/properties.rs @@ -2,9 +2,12 @@ pub struct Properties { pub props: Vec<(T, T)>, } -impl Properties { +impl Properties { #[allow(clippy::not_unsafe_ptr_arg_deref)] - pub fn from_ptr_raw(mut p: *const T) -> Vec { + pub fn from_ptr_raw(mut p: *const T) -> Vec + where + T: PartialEq, + { let mut res: Vec = Vec::new(); if !p.is_null() { @@ -22,7 +25,10 @@ impl Properties { } #[allow(clippy::not_unsafe_ptr_arg_deref)] - pub fn from_ptr(mut p: *const T) -> Option { + pub fn from_ptr(mut p: *const T) -> Option + where + T: PartialEq, + { let mut res = Self::default(); if !p.is_null() { @@ -45,6 +51,16 @@ impl Properties { Some(res) } + + /// Returns true when there is no property available. + pub fn is_empty(&self) -> bool { + self.props.is_empty() + } + + /// Returns the amount of key/value pairs available. + pub fn len(&self) -> usize { + self.props.len() + } } impl Default for Properties {