[Spice-devel] [spice-gtk v1 4/4] gtk-session: better variable name

Victor Toso victortoso at redhat.com
Wed Dec 5 15:52:44 UTC 2018


From: Victor Toso <me at victortoso.com>

Not saying it is perfect name but 'i' as index does not state much
after the for loop in g_memdup() and gtk_clipboard_set_with_owner().

Using number of elements as indexes is far from unusual so let's
rename it and reduce by one the single letter vars.

Also note that the change in indentation on arguments of
gtk_clipboard_set_with_owner() while renaming 'i' -> 'num_targets'.
Follow up patch will rename some callbacks, so keeping one argument
per line would reduce slightly the change set of patch set.

Signed-off-by: Victor Toso <victortoso at redhat.com>
---
 src/spice-gtk-session.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
index bf3c1fb..ef3faea 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -781,22 +781,22 @@ static gboolean clipboard_grab(SpiceMainChannel *main, guint selection,
     gboolean target_selected[SPICE_N_ELEMENTS(atom2agent)] = { FALSE, };
     gboolean found;
     GtkClipboard* cb;
-    int m, n, i;
+    int m, n;
+    int num_targets = 0;
 
     cb = get_clipboard_from_selection(s, selection);
     g_return_val_if_fail(cb != NULL, FALSE);
 
-    i = 0;
     for (n = 0; n < ntypes; ++n) {
         found = FALSE;
         for (m = 0; m < SPICE_N_ELEMENTS(atom2agent); m++) {
             if (atom2agent[m].vdagent == types[n] && !target_selected[m]) {
                 found = TRUE;
-                g_return_val_if_fail(i < SPICE_N_ELEMENTS(atom2agent), FALSE);
-                targets[i].target = (gchar*)atom2agent[m].xatom;
-                targets[i].info = m;
+                g_return_val_if_fail(num_targets < SPICE_N_ELEMENTS(atom2agent), FALSE);
+                targets[num_targets].target = (gchar*)atom2agent[m].xatom;
+                targets[num_targets].info = m;
                 target_selected[m] = TRUE;
-                i += 1;
+                num_targets += 1;
             }
         }
         if (!found) {
@@ -806,8 +806,8 @@ static gboolean clipboard_grab(SpiceMainChannel *main, guint selection,
     }
 
     g_free(s->clip_targets[selection]);
-    s->nclip_targets[selection] = i;
-    s->clip_targets[selection] = g_memdup(targets, sizeof(GtkTargetEntry) * i);
+    s->nclip_targets[selection] = num_targets;
+    s->clip_targets[selection] = g_memdup(targets, sizeof(GtkTargetEntry) * num_targets);
     /* Receiving a grab implies we've released our own grab */
     s->clip_grabbed[selection] = FALSE;
 
@@ -817,8 +817,12 @@ static gboolean clipboard_grab(SpiceMainChannel *main, guint selection,
         return TRUE;
     }
 
-    if (!gtk_clipboard_set_with_owner(cb, targets, i,
-                                      clipboard_get, clipboard_clear, G_OBJECT(self))) {
+    if (!gtk_clipboard_set_with_owner(cb,
+                                      targets,
+                                      num_targets,
+                                      clipboard_get,
+                                      clipboard_clear,
+                                      G_OBJECT(self))) {
         g_warning("clipboard grab failed");
         return FALSE;
     }
-- 
2.19.2



More information about the Spice-devel mailing list