Re: [PATCH 9/9] domain_conf: rewrite variable setting to ternary operator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/20/22 15:40, Peter Krempa wrote:
> On Wed, Jul 20, 2022 at 15:11:12 +0200, Kristina Hanicova wrote:
>> Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx>
>> ---
>>  src/conf/domain_conf.c | 8 ++------
>>  1 file changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
>> index e52f39c809..b600bfec31 100644
>> --- a/src/conf/domain_conf.c
>> +++ b/src/conf/domain_conf.c
>> @@ -4206,12 +4206,8 @@ virDomainObjGetOneDefState(virDomainObj *vm,
>>      if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
>>          return NULL;
>>  
>> -    if (live) {
>> -        if (flags & VIR_DOMAIN_AFFECT_LIVE)
>> -            *live = true;
>> -        else
>> -            *live = false;
>> -    }
>> +    if (live)
>> +        *live = (flags & VIR_DOMAIN_AFFECT_LIVE) ? true : false;
>>  
> 
> https://libvirt.org/coding-style.html#conditional-expressions
> 
> We suggest that new code avoids ternary operators.
> 
> I'd prefer if this patch is dropped.
> 

And what about:

if (live)
  *live = !!(flags & VIR_DOMAIN_AFFECT_LIVE);

? I agree that current version of the code is more verbose than it needs
to be. And while ternary operators might look bad, in fact I've
suggested them here:


https://gitlab.com/MichalPrivoznik/libvirt/-/commit/d2894d9f07ff2dde77bea53bb39dc8d0176eac85#f6109f17d3eb7394abb620a27ec56d76dd5220b0_4892_4878

Is there any better way?

Michal




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux