Re: [PATCH spice-gtk v3 1/4] gtk-session: use clear variable for array's size

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

 



Hi,

On Wed, May 24, 2017 at 05:05:47AM -0400, Frediano Ziglio wrote:
> > 
> > From: Victor Toso <me@xxxxxxxxxxxxxx>
> > 
> > By using 'num_types' variables, we have a clear variable with a clear
> > propose: It will track the number of VD_AGENT_CLIPBOARD types we are
> > storing in types[] array.
> > 
> > This new variable helps:
> > - removing one for that was counting the number stored types;
> > - reducing one for to the size of 'num_types'
> > 
> > A few extra comments were included to clarify what the logic should be
> > doing and a extra debug was included to point out situations where the
> > desktop has sent us valid clipboard data but none will be sent the
> > guest.
> > 
> > Signed-off-by: Victor Toso <victortoso@xxxxxxxxxx>
> > Signed-off-by: Victor Toso <me@xxxxxxxxxxxxxx>
> > ---
> >  src/spice-gtk-session.c | 34 +++++++++++++++++++---------------
> >  1 file changed, 19 insertions(+), 15 deletions(-)
> > 
> > diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
> > index cfdfc4c..83eaa3e 100644
> > --- a/src/spice-gtk-session.c
> > +++ b/src/spice-gtk-session.c
> > @@ -616,6 +616,7 @@ static void clipboard_get_targets(GtkClipboard
> > *clipboard,
> >  
> >      SpiceGtkSessionPrivate *s = self->priv;
> >      guint32 types[SPICE_N_ELEMENTS(atom2agent)] = { 0 };
> > +    gint num_types;
> >      char *name;
> >      int a, m, t;
> >      int selection;
> > @@ -635,38 +636,41 @@ static void clipboard_get_targets(GtkClipboard
> > *clipboard,
> >          }
> >      }
> >  
> > +    /* Set all Atoms that matches our current protocol implementation */
> > +    num_types = 0;
> >      for (a = 0; a < n_atoms; a++) {
> >          name = gdk_atom_name(atoms[a]);
> >          for (m = 0; m < SPICE_N_ELEMENTS(atom2agent); m++) {
> >              if (strcasecmp(name, atom2agent[m].xatom) != 0) {
> >                  continue;
> >              }
> > -            /* found match */
> > -            for (t = 0; t < SPICE_N_ELEMENTS(atom2agent); t++) {
> > +
> > +            /* check if type is already in list */
> > +            for (t = 0; t < num_types; t++) {
> >                  if (types[t] == atom2agent[m].vdagent) {
> > -                    /* type already in list */
> > -                    break;
> > -                }
> > -                if (types[t] == 0) {
> > -                    /* add type to empty slot */
> > -                    types[t] = atom2agent[m].vdagent;
> >                      break;
> >                  }
> >              }
> > -            break;
> > +
> > +            if (types[t] == 0) {
>
> t == num_types would avoid the initialization.

Yeah, you are right. I changed this bit here but I'll remove the
initialization in a follow up patch that moves these variables to
beginning of the function.


>
> > +                /* add type to empty slot */
> > +                types[t] = atom2agent[m].vdagent;
> > +                num_types++;
> > +            }
> >          }
> >          g_free(name);
> >      }
> > -    for (t = 0; t < SPICE_N_ELEMENTS(atom2agent); t++) {
> > -        if (types[t] == 0) {
> > -            break;
> > -        }
> > +
> > +    if (num_types == 0) {
> > +        SPICE_DEBUG("No GdkAtoms will be sent from %d", n_atoms);
> > +        return;
> >      }
> > -    if (!s->clip_grabbed[selection] && t > 0) {
> > +
> > +    if (!s->clip_grabbed[selection]) {
> >          s->clip_grabbed[selection] = TRUE;
> >  
> >          if (spice_main_agent_test_capability(s->main,
> >          VD_AGENT_CAP_CLIPBOARD_BY_DEMAND))
> > -            spice_main_clipboard_selection_grab(s->main, selection, types,
> > t);
> > +            spice_main_clipboard_selection_grab(s->main, selection, types,
> > num_types);
> >          /* Sending a grab causes the agent to do an implicit release */
> >          s->nclip_targets[selection] = 0;
> >      }
>
> Either way,
>
> Acked-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
>
> Frediano

Diff of this patch will be just:
-            if (types[t] == 0) {
+            if (t == num_types) {

So I take the ack, many thanks for the review once more :)

Cheers,

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]