lkml.org 
[lkml]   [2013]   [Oct]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 6/7] perf util: Add findnew method to intlist
Em Sat, Sep 28, 2013 at 01:13:03PM -0600, David Ahern escreveu:
> Similar to other findnew based methods if the requested
> object is not found, add it to the list.

> +struct int_node *intlist__findnew(struct intlist *ilist, int i)
> +{
> + struct int_node *node = intlist__find(ilist, i);
> +
> + if ((node == NULL) && (intlist__add(ilist, i) == 0))
> + node = intlist__find(ilist, i);
> +
> + return node;


This is what I should have pointed out earlier: Can't we have a
find_and_add_if_not_found routine as we have elsewhere?

Calling intlist__find() after intlist__add() looks really ugly :-\

Please take a look at my perf/core branch, several patches of this
series are there, one with minor change.

- Arnaldo

> +}
> +
> static int intlist__parse_list(struct intlist *ilist, const char *s)
> {
> char *sep;
> diff --git a/tools/perf/util/intlist.h b/tools/perf/util/intlist.h
> index 0eb00ac..aa6877d 100644
> --- a/tools/perf/util/intlist.h
> +++ b/tools/perf/util/intlist.h
> @@ -24,6 +24,7 @@ int intlist__add(struct intlist *ilist, int i);
>
> struct int_node *intlist__entry(const struct intlist *ilist, unsigned int idx);
> struct int_node *intlist__find(struct intlist *ilist, int i);
> +struct int_node *intlist__findnew(struct intlist *ilist, int i);
>
> static inline bool intlist__has_entry(struct intlist *ilist, int i)
> {
> --
> 1.7.10.1


\
 
 \ /
  Last update: 2013-10-08 15:41    [W:0.086 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site