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

From: Jiri Olsa
Date: Wed Sep 22 2021 - 16:59:42 EST


On Fri, Sep 17, 2021 at 11:35:10PM -0700, Ian Rogers wrote:

SNIP

>
> +struct hashmap *ids__union(struct hashmap *ids1, struct hashmap *ids2)
> +{
> + size_t bkt;
> + struct hashmap_entry *cur;
> + int ret;
> + struct expr_id_data *old_data = NULL;
> + char *old_key = NULL;
> +
> + if (!ids1)
> + return ids2;
> +
> + if (!ids2)
> + return ids1;
> +
> + if (hashmap__size(ids1) < hashmap__size(ids2)) {
> + struct hashmap *tmp = ids1;
> +
> + ids1 = ids2;
> + ids2 = tmp;
> + }
> + hashmap__for_each_entry(ids2, cur, bkt) {
> + ret = hashmap__set(ids1, cur->key, cur->value,
> + (const void **)&old_key, (void **)&old_data);
> + free(old_key);
> + free(old_data);
> +
> + if (ret)
> + break;

should we return NULL in here?

jirka

> + }
> + hashmap__free(ids2);
> + return ids1;
> +}
> +
> +/* Caller must make sure id is allocated */
> +int expr__add_id(struct expr_parse_ctx *ctx, const char *id)
> +{
> + return ids__insert(ctx->ids, id, ctx->parent);
> +}
> +

SNIP