Il mar 22 ott 2024, 21:46 Kevin Wolf <kw...@redhat.com> ha scritto:

> >              info: $prop,
> >              offset: ::core::mem::offset_of!($state, $field)
> >                  .try_into()
> >                  .expect("Could not fit offset value to type"),
> > -            bitnr: 0,
> > -            bitmask: 0,
> >              set_default: true,
> >              defval: $crate::bindings::Property__bindgen_ty_1 { u:
> $defval.into() },
> > -            arrayoffset: 0,
> > -            arrayinfo: ::core::ptr::null(),
> > -            arrayfieldsize: 0,
> > -            link_type: ::core::ptr::null(),
> > +            ..unsafe {
> ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init()
> }
>
> But is it really worth introducing unsafe code just for a more compact
> notation? If the compiler doesn't actually understand the pattern, it
> might even be less efficient than what we had (i.e. if it really creates
> the zeroed object and copies stuff over).
>

It goes away later in the series (patch 11 replaces it with a more
manageable "Zeroable::ZERO"), but I wanted to split the patches in "parts
that change existing code" and "parts that introduce new concepts".

I agree that it's not optimal either way, I went like this because at this
point this "unsafe { zeroed() }" idiom is present several times in the code
and one more doesn't really change much.

Paolo


> Kevin
>
>

Reply via email to