summaryrefslogtreecommitdiffstats
path: root/tools/perf/util/intlist.c
diff options
context:
space:
mode:
authorDavid Ahern <dsahern@gmail.com>2013-10-08 21:26:52 -0600
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-10-14 10:28:48 -0300
commit813335b8b27d9ceeb67a073f501ada8b8dde37a7 (patch)
tree6089b90d2cefe9c93576dfbf7146c486d4cf6a2b /tools/perf/util/intlist.c
parent87f918685a452be514d060a09eeb4e0c91422e86 (diff)
downloadop-kernel-dev-813335b8b27d9ceeb67a073f501ada8b8dde37a7.zip
op-kernel-dev-813335b8b27d9ceeb67a073f501ada8b8dde37a7.tar.gz
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.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/tools/perf/util/intlist.c b/tools/perf/util/intlist.c
index 826d7b3..89715b6 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;
OpenPOWER on IntegriCloud