Re: [PATCH v2 7/7] perf expr: Migrate expr ids table to a hashmap

From: Jiri Olsa
Date: Fri May 15 2020 - 18:42:01 EST


On Fri, May 15, 2020 at 09:50:07AM -0700, Ian Rogers wrote:

SNIP

> diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c
> index 8b4ce704a68d..f64ab91c432b 100644
> --- a/tools/perf/util/expr.c
> +++ b/tools/perf/util/expr.c
> @@ -4,25 +4,76 @@
> #include "expr.h"
> #include "expr-bison.h"
> #include "expr-flex.h"
> +#include <linux/kernel.h>
>
> #ifdef PARSER_DEBUG
> extern int expr_debug;
> #endif
>
> +static size_t key_hash(const void *key, void *ctx __maybe_unused)
> +{
> + const char *str = (const char *)key;
> + size_t hash = 0;
> +
> + while (*str != '\0') {
> + hash *= 31;
> + hash += *str;
> + str++;
> + }
> + return hash;
> +}
> +
> +static bool key_equal(const void *key1, const void *key2,
> + void *ctx __maybe_unused)
> +{
> + return !strcmp((const char *)key1, (const char *)key2);

should that be strcasecmp ? would it affect the key_hash as well?

jirka