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

From: Jiri Olsa
Date: Fri Jan 15 2021 - 05:10:18 EST


On Tue, Jan 12, 2021 at 03:04:33PM -0800, 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 this return NULL instead?

> + }
> + hashmap__free(ids2);
> + return ids1;
> +}
> +

SNIP