From 85b02f6c2b15d4d9dca1083f161da6236e0fd80c Mon Sep 17 00:00:00 2001 From: CismonX Date: Sun, 9 Mar 2025 15:44:29 +0800 Subject: [PATCH] backend_firefox, fs_ops: store hashcode in entry Trade a bit of memory for hashmap rehash/remove efficiency. --- src/backend_firefox.c | 12 ++++++++---- src/fs_ops.c | 7 +++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/backend_firefox.c b/src/backend_firefox.c index e1054ee..6c163b2 100644 --- a/src/backend_firefox.c +++ b/src/backend_firefox.c @@ -162,9 +162,11 @@ struct bookmark_lcookie { }; struct bookmark_dentry { - uint64_t id; - size_t name_len; - char name[]; + uint64_t id; + unsigned long hashcode; + + size_t name_len; + char name[]; }; struct bookmark_name_key { @@ -530,6 +532,7 @@ fsck_apply ( dentry = xmalloc(sizeof(*dentry) + name_len); dentry->id = id; + dentry->hashcode = hashcode; dentry->name_len = name_len; memcpy(dentry->name, name, name_len); @@ -2454,6 +2457,7 @@ bookmark_list_cb ( if (ctx->status == 0 && ctx->check_name && dentry == NULL) { dentry = xmalloc(sizeof(*dentry) + name_len); dentry->id = id; + dentry->hashcode = hashcode; dentry->name_len = name_len; memcpy(dentry->name, name, name_len); @@ -2522,7 +2526,7 @@ dentmap_hash ( ) { struct bookmark_dentry const *dentry = entry; - return hash_digest(dentry->name, dentry->name_len); + return dentry->hashcode; } static void diff --git a/src/fs_ops.c b/src/fs_ops.c index d901678..676f7bb 100644 --- a/src/fs_ops.c +++ b/src/fs_ops.c @@ -126,7 +126,9 @@ enum { }; struct fs_file_handle { - uint64_t id; + uint64_t id; + unsigned long hashcode; + uint32_t refcount; uint32_t flags; @@ -491,6 +493,7 @@ bm_fh_new ( fh = xmalloc(sizeof(*fh)); *fh = (struct fs_file_handle) { .id = id, + .hashcode = hashcode, .refcount = 1, }; hashmap_insert(ctx.fh_map, hashcode, fh); @@ -1285,7 +1288,7 @@ fh_entry_hash ( ) { struct fs_file_handle const *fh = entry; - return hash_digest(&fh->id, sizeof(fuse_ino_t)); + return fh->hashcode; } static int