[Spice-devel] [spicy PATCH 6/7 v4] spicy: Changed duplicit lines to for loop

Christophe Fergeau cfergeau at redhat.com
Tue Jun 16 04:22:48 PDT 2015


short log: "Replace duplicated code with a for loop" ?
ACK. I usually use unsigned int for loop indexes, but this is not really
important here.

Christophe

On Tue, Jun 16, 2015 at 11:41:56AM +0200, Lukas Venhoda wrote:
> Changed piece of code working with fixed size array into a for loop.
> ---
> Changes since v3
>  - New patch
> ---
>  src/spicy-connect.c | 17 ++++++-----------
>  1 file changed, 6 insertions(+), 11 deletions(-)
> 
> diff --git a/src/spicy-connect.c b/src/spicy-connect.c
> index c5f1dfb..7834e3a 100644
> --- a/src/spicy-connect.c
> +++ b/src/spicy-connect.c
> @@ -111,6 +111,7 @@ static void recent_selection_changed_dialog_cb(GtkRecentChooser *chooser, gpoint
>      gchar *txt = NULL;
>      const gchar *uri;
>      SpiceSession *session = data;
> +    int i;
> 
>      info = gtk_recent_chooser_get_current_item(chooser);
>      if (info == NULL)
> @@ -121,17 +122,11 @@ static void recent_selection_changed_dialog_cb(GtkRecentChooser *chooser, gpoint
> 
>      g_object_set(session, "uri", uri, NULL);
> 
> -    g_object_get(session, "host", &txt, NULL);
> -    gtk_entry_set_text(GTK_ENTRY(connect_entries[0].entry), txt ? txt : "");
> -    g_free(txt);
> -
> -    g_object_get(session, "port", &txt, NULL);
> -    gtk_entry_set_text(GTK_ENTRY(connect_entries[1].entry), txt ? txt : "");
> -    g_free(txt);
> -
> -    g_object_get(session, "tls-port", &txt, NULL);
> -    gtk_entry_set_text(GTK_ENTRY(connect_entries[2].entry), txt ? txt : "");
> -    g_free(txt);
> +    for (i = 0; i < SPICE_N_ELEMENTS(connect_entries); i++) {
> +        g_object_get(session, connect_entries[i].prop, &txt, NULL);
> +        gtk_entry_set_text(GTK_ENTRY(connect_entries[i].entry), txt ? txt : "");
> +        g_free(txt);
> +    }
> 
>      gtk_recent_info_unref(info);
>  }
> --
> 2.4.2
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20150616/0bc0da70/attachment.sig>


More information about the Spice-devel mailing list