Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

David Ahern and committed by
Arnaldo Carvalho de Melo
813335b8 87f91868

+44 -7
+18 -4
tools/perf/util/intlist.c
··· 58 58 rblist__remove_node(&ilist->rblist, &node->rb_node); 59 59 } 60 60 61 - struct int_node *intlist__find(struct intlist *ilist, int i) 61 + static struct int_node *__intlist__findnew(struct intlist *ilist, 62 + int i, bool create) 62 63 { 63 - struct int_node *node; 64 + struct int_node *node = NULL; 64 65 struct rb_node *rb_node; 65 66 66 67 if (ilist == NULL) 67 68 return NULL; 68 69 69 - node = NULL; 70 - rb_node = rblist__find(&ilist->rblist, (void *)((long)i)); 70 + if (create) 71 + rb_node = rblist__findnew(&ilist->rblist, (void *)((long)i)); 72 + else 73 + rb_node = rblist__find(&ilist->rblist, (void *)((long)i)); 74 + 71 75 if (rb_node) 72 76 node = container_of(rb_node, struct int_node, rb_node); 73 77 74 78 return node; 79 + } 80 + 81 + struct int_node *intlist__find(struct intlist *ilist, int i) 82 + { 83 + return __intlist__findnew(ilist, i, false); 84 + } 85 + 86 + struct int_node *intlist__findnew(struct intlist *ilist, int i) 87 + { 88 + return __intlist__findnew(ilist, i, true); 75 89 } 76 90 77 91 static int intlist__parse_list(struct intlist *ilist, const char *s)
+1
tools/perf/util/intlist.h
··· 24 24 25 25 struct int_node *intlist__entry(const struct intlist *ilist, unsigned int idx); 26 26 struct int_node *intlist__find(struct intlist *ilist, int i); 27 + struct int_node *intlist__findnew(struct intlist *ilist, int i); 27 28 28 29 static inline bool intlist__has_entry(struct intlist *ilist, int i) 29 30 {
+24 -3
tools/perf/util/rblist.c
··· 48 48 rblist->node_delete(rblist, rb_node); 49 49 } 50 50 51 - struct rb_node *rblist__find(struct rblist *rblist, const void *entry) 51 + static struct rb_node *__rblist__findnew(struct rblist *rblist, 52 + const void *entry, 53 + bool create) 52 54 { 53 55 struct rb_node **p = &rblist->entries.rb_node; 54 - struct rb_node *parent = NULL; 56 + struct rb_node *parent = NULL, *new_node = NULL; 55 57 56 58 while (*p != NULL) { 57 59 int rc; ··· 69 67 return parent; 70 68 } 71 69 72 - return NULL; 70 + if (create) { 71 + new_node = rblist->node_new(rblist, entry); 72 + if (new_node) { 73 + rb_link_node(new_node, parent, p); 74 + rb_insert_color(new_node, &rblist->entries); 75 + ++rblist->nr_entries; 76 + } 77 + } 78 + 79 + return new_node; 80 + } 81 + 82 + struct rb_node *rblist__find(struct rblist *rblist, const void *entry) 83 + { 84 + return __rblist__findnew(rblist, entry, false); 85 + } 86 + 87 + struct rb_node *rblist__findnew(struct rblist *rblist, const void *entry) 88 + { 89 + return __rblist__findnew(rblist, entry, true); 73 90 } 74 91 75 92 void rblist__init(struct rblist *rblist)
+1
tools/perf/util/rblist.h
··· 32 32 int rblist__add_node(struct rblist *rblist, const void *new_entry); 33 33 void rblist__remove_node(struct rblist *rblist, struct rb_node *rb_node); 34 34 struct rb_node *rblist__find(struct rblist *rblist, const void *entry); 35 + struct rb_node *rblist__findnew(struct rblist *rblist, const void *entry); 35 36 struct rb_node *rblist__entry(const struct rblist *rblist, unsigned int idx); 36 37 37 38 static inline bool rblist__empty(const struct rblist *rblist)