diff options
author | David Ahern <dsahern@gmail.com> | 2013-10-09 05:26:52 +0200 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-10-14 15:28:48 +0200 |
commit | 813335b8b27d9ceeb67a073f501ada8b8dde37a7 (patch) | |
tree | 6089b90d2cefe9c93576dfbf7146c486d4cf6a2b /tools/perf/util/intlist.c | |
parent | perf trace: Improve the error messages (diff) | |
download | linux-813335b8b27d9ceeb67a073f501ada8b8dde37a7.tar.xz linux-813335b8b27d9ceeb67a073f501ada8b8dde37a7.zip |
perf util: Add findnew method to intlist
Similar to other findnew based methods if the requested object is not
found, add it to the list.
v2: followed format of other findnew methods per acme's request
Signed-off-by: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1381289214-24885-2-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/intlist.c')
-rw-r--r-- | tools/perf/util/intlist.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/tools/perf/util/intlist.c b/tools/perf/util/intlist.c index 826d7b38c9a0..89715b64a315 100644 --- a/tools/perf/util/intlist.c +++ b/tools/perf/util/intlist.c @@ -58,22 +58,36 @@ void intlist__remove(struct intlist *ilist, struct int_node *node) rblist__remove_node(&ilist->rblist, &node->rb_node); } -struct int_node *intlist__find(struct intlist *ilist, int i) +static struct int_node *__intlist__findnew(struct intlist *ilist, + int i, bool create) { - struct int_node *node; + struct int_node *node = NULL; struct rb_node *rb_node; if (ilist == NULL) return NULL; - node = NULL; - rb_node = rblist__find(&ilist->rblist, (void *)((long)i)); + if (create) + rb_node = rblist__findnew(&ilist->rblist, (void *)((long)i)); + else + rb_node = rblist__find(&ilist->rblist, (void *)((long)i)); + if (rb_node) node = container_of(rb_node, struct int_node, rb_node); return node; } +struct int_node *intlist__find(struct intlist *ilist, int i) +{ + return __intlist__findnew(ilist, i, false); +} + +struct int_node *intlist__findnew(struct intlist *ilist, int i) +{ + return __intlist__findnew(ilist, i, true); +} + static int intlist__parse_list(struct intlist *ilist, const char *s) { char *sep; |