Re: [PATCH v8 5/8] perf metric: Add utilities to work on ids map.

From: Jiri Olsa
Date: Wed Sep 22 2021 - 16:58:44 EST


SNIP

> diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c
> index adf16bb7571a..34b51ca5e87f 100644
> --- a/tools/perf/util/expr.c
> +++ b/tools/perf/util/expr.c
> @@ -59,8 +59,48 @@ static bool key_equal(const void *key1, const void *key2,
> return !strcmp((const char *)key1, (const char *)key2);
> }
>
> -/* Caller must make sure id is allocated */
> -int expr__add_id(struct expr_parse_ctx *ctx, const char *id)
> +struct hashmap *ids__new(void)
> +{
> + return hashmap__new(key_hash, key_equal, NULL);
> +}
> +
> +void ids__free(struct hashmap *ids)
> +{
> + struct hashmap_entry *cur;
> + size_t bkt;
> +
> + if (ids == NULL)
> + return;
> +
> +#ifdef PARSER_DEBUG
> + fprintf(stderr, "freeing ids: ");
> + ids__print(ids);
> + fprintf(stderr, "\n");
> +#endif

hum, is this intended or forgotten debug leftover?

jirka

> +
> + hashmap__for_each_entry(ids, cur, bkt) {
> + free((char *)cur->key);
> + free(cur->value);
> + }
> +
> + hashmap__free(ids);
> +}
> +
> +void ids__print(struct hashmap *ids)

SNIP