diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2009-07-11 11:18:34 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-07-11 13:20:25 -0400 |
commit | 27d0fd410c3cee00ece2e55f4354a7a9ec1a6a6a (patch) | |
tree | a81c59fef46f70e700e86f04a3bf5b90d7cd17b9 /tools/perf | |
parent | 60c1baf1248e00d423604f018c8af1cf750ad885 (diff) |
strlist: Introduce strlist__entry and strlist__nr_entries methods
The strlist__entry method allows accessing strlists like an
array, will be used in the 'perf report' to access the first
entry.
We now keep the nr_entries so that we can check if we have just
one entry, will be used in 'perf report' to improve the output
by showing just at the top when we have just, say, one DSO.
While at it use nr_entries to optimize strlist__is_empty by not
using the far more costly rb_first based implementation.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-2-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/strlist.c | 20 | ||||
-rw-r--r-- | tools/perf/util/strlist.h | 11 |
2 files changed, 27 insertions, 4 deletions
diff --git a/tools/perf/util/strlist.c b/tools/perf/util/strlist.c index 025a78edfffe..7ad38171dc2b 100644 --- a/tools/perf/util/strlist.c +++ b/tools/perf/util/strlist.c | |||
@@ -64,6 +64,7 @@ int strlist__add(struct strlist *self, const char *new_entry) | |||
64 | 64 | ||
65 | rb_link_node(&sn->rb_node, parent, p); | 65 | rb_link_node(&sn->rb_node, parent, p); |
66 | rb_insert_color(&sn->rb_node, &self->entries); | 66 | rb_insert_color(&sn->rb_node, &self->entries); |
67 | ++self->nr_entries; | ||
67 | 68 | ||
68 | return 0; | 69 | return 0; |
69 | } | 70 | } |
@@ -155,8 +156,9 @@ struct strlist *strlist__new(bool dupstr, const char *slist) | |||
155 | struct strlist *self = malloc(sizeof(*self)); | 156 | struct strlist *self = malloc(sizeof(*self)); |
156 | 157 | ||
157 | if (self != NULL) { | 158 | if (self != NULL) { |
158 | self->entries = RB_ROOT; | 159 | self->entries = RB_ROOT; |
159 | self->dupstr = dupstr; | 160 | self->dupstr = dupstr; |
161 | self->nr_entries = 0; | ||
160 | if (slist && strlist__parse_list(self, slist) != 0) | 162 | if (slist && strlist__parse_list(self, slist) != 0) |
161 | goto out_error; | 163 | goto out_error; |
162 | } | 164 | } |
@@ -182,3 +184,17 @@ void strlist__delete(struct strlist *self) | |||
182 | free(self); | 184 | free(self); |
183 | } | 185 | } |
184 | } | 186 | } |
187 | |||
188 | struct str_node *strlist__entry(const struct strlist *self, unsigned int idx) | ||
189 | { | ||
190 | struct rb_node *nd; | ||
191 | |||
192 | for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { | ||
193 | struct str_node *pos = rb_entry(nd, struct str_node, rb_node); | ||
194 | |||
195 | if (!idx--) | ||
196 | return pos; | ||
197 | } | ||
198 | |||
199 | return NULL; | ||
200 | } | ||
diff --git a/tools/perf/util/strlist.h b/tools/perf/util/strlist.h index 2fdcfee87586..921818e44a54 100644 --- a/tools/perf/util/strlist.h +++ b/tools/perf/util/strlist.h | |||
@@ -11,7 +11,8 @@ struct str_node { | |||
11 | 11 | ||
12 | struct strlist { | 12 | struct strlist { |
13 | struct rb_root entries; | 13 | struct rb_root entries; |
14 | bool dupstr; | 14 | unsigned int nr_entries; |
15 | bool dupstr; | ||
15 | }; | 16 | }; |
16 | 17 | ||
17 | struct strlist *strlist__new(bool dupstr, const char *slist); | 18 | struct strlist *strlist__new(bool dupstr, const char *slist); |
@@ -21,11 +22,17 @@ void strlist__remove(struct strlist *self, struct str_node *sn); | |||
21 | int strlist__load(struct strlist *self, const char *filename); | 22 | int strlist__load(struct strlist *self, const char *filename); |
22 | int strlist__add(struct strlist *self, const char *str); | 23 | int strlist__add(struct strlist *self, const char *str); |
23 | 24 | ||
25 | struct str_node *strlist__entry(const struct strlist *self, unsigned int idx); | ||
24 | bool strlist__has_entry(struct strlist *self, const char *entry); | 26 | bool strlist__has_entry(struct strlist *self, const char *entry); |
25 | 27 | ||
26 | static inline bool strlist__empty(const struct strlist *self) | 28 | static inline bool strlist__empty(const struct strlist *self) |
27 | { | 29 | { |
28 | return rb_first(&self->entries) == NULL; | 30 | return self->nr_entries == 0; |
31 | } | ||
32 | |||
33 | static inline unsigned int strlist__nr_entries(const struct strlist *self) | ||
34 | { | ||
35 | return self->nr_entries; | ||
29 | } | 36 | } |
30 | 37 | ||
31 | int strlist__parse_list(struct strlist *self, const char *s); | 38 | int strlist__parse_list(struct strlist *self, const char *s); |