[PATCH v1 09/26] perf fncache: Use generic hashmap for fncache
From: Ian Rogers
Date: Fri Nov 13 2026 - 16:54:13 EST
Convert fncache in tools/perf/util/fncache.c to
DECLARE_HASHMAP(fncache_map, char *, bool) and use the type-checked
hashmap__* wrappers, eliminating the manual long temporary conversion on
bool lookups.
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/fncache.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/tools/perf/util/fncache.c b/tools/perf/util/fncache.c
index 04ea150bc7cd..f00367b5f265 100644
--- a/tools/perf/util/fncache.c
+++ b/tools/perf/util/fncache.c
@@ -8,7 +8,9 @@
#include "fncache.h"
#include "hashmap.h"
-static struct hashmap *fncache;
+DECLARE_HASHMAP(fncache_map, char *, bool);
+
+static struct fncache_map *fncache;
static size_t fncache__hash(long key, void *ctx __maybe_unused)
{
@@ -22,10 +24,10 @@ static bool fncache__equal(long key1, long key2, void *ctx __maybe_unused)
static void fncache__init(void)
{
- fncache = hashmap__new(fncache__hash, fncache__equal, /*ctx=*/NULL);
+ fncache = fncache_map__new(fncache__hash, fncache__equal, /*ctx=*/NULL);
}
-static struct hashmap *fncache__get(void)
+static struct fncache_map *fncache__get(void)
{
static pthread_once_t fncache_once = PTHREAD_ONCE_INIT;
@@ -36,23 +38,18 @@ static struct hashmap *fncache__get(void)
static bool lookup_fncache(const char *name, bool *res)
{
- struct hashmap *map = fncache__get();
- long val;
-
- if (!map || !hashmap__find(map, name, &val))
- return false;
+ struct fncache_map *map = fncache__get();
- *res = (val != 0);
- return true;
+ return map && hashmap__find(map, name, res);
}
static void update_fncache(const char *name, bool res)
{
- struct hashmap *map = fncache__get();
+ struct fncache_map *map = fncache__get();
char *old_key = NULL, *key = strdup(name);
if (map && key) {
- hashmap__set(map, key, res, &old_key, /*old_value*/NULL);
+ hashmap__set(map, key, res, &old_key, /*old_value=*/NULL);
free(old_key);
} else {
free(key);
--
2.56.1.703.gf848ed807c-goog