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

Re: [Xen-devel] [PATCH V4 14/24] libxl: introduce libxl_key_value_list_length



On Tue, May 06, 2014 at 02:50:04PM +0100, Ian Campbell wrote:
> On Thu, 2014-05-01 at 13:58 +0100, Wei Liu wrote:
> > Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
> > ---
> >  tools/libxl/libxl.c |   12 ++++++++++++
> >  tools/libxl/libxl.h |    1 +
> >  2 files changed, 13 insertions(+)
> > 
> > diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
> > index dbba7ca..08c4f54 100644
> > --- a/tools/libxl/libxl.c
> > +++ b/tools/libxl/libxl.c
> > @@ -216,6 +216,18 @@ int libxl_string_list_length(const libxl_string_list 
> > *psl)
> >      return i;
> >  }
> >  
> > +int libxl_key_value_list_length(libxl_key_value_list *pkvl)
> > +{
> > +    int i = 0;
> > +    libxl_key_value_list kvl = *pkvl;
> > +
> > +    if (kvl)
> > +        while (kvl[i])
> > +            i += 2;
> > +
> > +    return i / 2;
> 
> "+= 2" *and* "/ 2"?
> 
> Oh I see, values can be NULL.
> 
> It might sound stupid but:
>       while(kvl[i]) {
>               i++; /* Key */
>               i++; /* Values, could be NULL */
> might be clearer?
> 
> Or:
>       while (kvl[2*i]) /* Only check keys */
>               i++
>       return i;
> 
> The key think about both proposals is the presence of a comment ;-)
> 

NP. I will use the second form.

Wei.

> Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.