[Spice-devel] [spice-gtk v1] usb-device-widget: remove goto/label

Eduardo Lima (Etrunko) etrunko at redhat.com
Fri Apr 20 13:33:21 UTC 2018


On 17/04/18 04:40, Victor Toso wrote:
> From: Victor Toso <me at victortoso.com>
> 
> The 'end' label is used only once and can be replaced by moving the
> code into the existing 'if (!devices)'.
> 
> For convenience this patch also:
> * Explicit check against NULL
> * Added curly brackets to the moved 'for'
> * Moved variable 'i' to inner scope
> 

The code as is today does not bother me, but this patch is also fine for
me. Either way, if you think it is an improvement in readability, push it ;)

Reviewed-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>

> Signed-off-by: Victor Toso <victortoso at redhat.com>
> ---
>  src/usb-device-widget.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/src/usb-device-widget.c b/src/usb-device-widget.c
> index a3c0910..6dd3617 100644
> --- a/src/usb-device-widget.c
> +++ b/src/usb-device-widget.c
> @@ -187,7 +187,6 @@ static void spice_usb_device_widget_constructed(GObject *gobject)
>      GPtrArray *devices = NULL;
>      GError *err = NULL;
>      gchar *str;
> -    int i;
>  
>      self = SPICE_USB_DEVICE_WIDGET(gobject);
>      priv = self->priv;
> @@ -218,15 +217,15 @@ static void spice_usb_device_widget_constructed(GObject *gobject)
>                       G_CALLBACK(device_error_cb), self);
>  
>      devices = spice_usb_device_manager_get_devices(priv->manager);
> -    if (!devices)
> -        goto end;
> -
> -    for (i = 0; i < devices->len; i++)
> -        device_added_cb(NULL, g_ptr_array_index(devices, i), self);
> +    if (devices != NULL) {
> +        int i;
> +        for (i = 0; i < devices->len; i++) {
> +            device_added_cb(NULL, g_ptr_array_index(devices, i), self);
> +        }
>  
> -    g_ptr_array_unref(devices);
> +        g_ptr_array_unref(devices);
> +    }
>  
> -end:
>      spice_usb_device_widget_update_status(self);
>  }
>  
> 


-- 
Eduardo de Barros Lima (Etrunko)
Software Engineer - RedHat
etrunko at redhat.com


More information about the Spice-devel mailing list