Re: GNOME CVS: libbonobo michael



Michael Meeks <michael ximian com> writes: 
> bonobo_control_set_pb (control, pb)
> {
>         if (control->pb == pb)
>                 return;
> 
>         if (control->pb)
>                 bonobo_object_unref (control->pb);
> 
>         if (pb)
>                 control->pb = bonobo_object_ref (pb);
>         else
>                 control->pb = NULL;
> }
> 
>         but;
> 
> bonobo_control_set_pb (control, pb)
> {
>         if (control->pb == pb)
>                 return;
> 
>         bonobo_object_unref (control->pb);
>         control->pb = bonobo_object_ref (pb);
> }
> 
>         Which is more lucid, and less prone to people forgetting the NULL
> path to set the value to NULL.

I usually write:

bonobo_control_set_pb (control, pb)
{
    if (pb)
       bonobo_object_ref (pb);

    if (control->pb)
       bonobo_object_unref (control->pb);

    control->pb = pb;
}

Which is just as short, and clarifies that either control->pb or pb
could be NULL.

Havoc



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