]> granicus.if.org Git - neomutt/commitdiff
refactor hash
authorRichard Russon <rich@flatcap.org>
Sat, 22 Dec 2018 21:28:22 +0000 (21:28 +0000)
committerRichard Russon <rich@flatcap.org>
Sat, 22 Dec 2018 22:18:12 +0000 (22:18 +0000)
15 files changed:
config/set.c
email/thread.c
imap/util.c
init.c
maildir/maildir.c
maildir/mh.c
mbox/mbox.c
mutt/group.c
mutt/hash.c
mutt/hash.h
mutt/history.c
mutt_thread.c
mx.c
nntp/newsrc.c
nntp/nntp.c

index 30ece0443ca1b4e6c698a3fb59d7b2da6f39e722..f1e4c47a649e35ab03571d4dca70b05416bc7ede 100644 (file)
@@ -45,7 +45,7 @@ struct ConfigSetType RegisteredTypes[18] = {
 };
 
 /**
- * destroy - Callback function for the Hash Table - Implements ::hash_destructor_t
+ * destroy - Callback function for the Hash Table - Implements ::hashelem_free_t
  * @param type Object type, e.g. #DT_STRING
  * @param obj  Object to destroy
  * @param data ConfigSet associated with the object
@@ -179,7 +179,7 @@ void cs_free(struct ConfigSet **cs)
   if (!cs || !*cs)
     return; /* LCOV_EXCL_LINE */
 
-  mutt_hash_destroy(&(*cs)->hash);
+  mutt_hash_free(&(*cs)->hash);
   FREE(cs);
 }
 
index 98341afbb2aef8cb1312324fa8bf74499b76eee4..2b4443cd326f1814a710f69f843d3860e1068347 100644 (file)
@@ -101,7 +101,7 @@ void insert_message(struct MuttThread **new, struct MuttThread *newparent,
 }
 
 /**
- * thread_hash_destructor - Hash Destructor callback - Implements ::hash_destructor_t
+ * thread_hash_destructor - Hash Destructor callback - Implements ::hashelem_free_t
  */
 void thread_hash_destructor(int type, void *obj, intptr_t data)
 {
index f0ca6a04bd7e7684a42d0a45c0527aca23f591b2..2411d364a6ca5c00c730bd51fcc6ba558efc5375 100644 (file)
@@ -202,7 +202,7 @@ struct ImapMboxData *imap_mdata_new(struct ImapAccountData *adata, const char *n
  */
 void imap_mdata_cache_reset(struct ImapMboxData *mdata)
 {
-  mutt_hash_destroy(&mdata->uid_hash);
+  mutt_hash_free(&mdata->uid_hash);
   FREE(&mdata->msn_index);
   mdata->msn_index_size = 0;
   mdata->max_msn = 0;
diff --git a/init.c b/init.c
index 12c683c67c4dacd2a3e7d802262def9007ce631b..cd0ab2a90634daf9c53233420d54e068b5e6ca62 100644 (file)
--- a/init.c
+++ b/init.c
@@ -2787,9 +2787,9 @@ void mutt_free_opts(void)
   mutt_regexlist_free(&UnSubscribedLists);
 
   mutt_grouplist_free();
-  mutt_hash_destroy(&ReverseAliases);
-  mutt_hash_destroy(&TagFormats);
-  mutt_hash_destroy(&TagTransforms);
+  mutt_hash_free(&ReverseAliases);
+  mutt_hash_free(&TagFormats);
+  mutt_hash_free(&TagTransforms);
 
   /* Lists of strings */
   mutt_list_free(&AlternativeOrderList);
index 32e94e84f71241445e4087489af75f7520af3508..cbe3546466e47ea2d0dc28cbb51bc1ee2b3a8ad2 100644 (file)
@@ -512,7 +512,7 @@ int maildir_mbox_check(struct Context *ctx, int *index_hint)
   }
 
   /* destroy the file name hash */
-  mutt_hash_destroy(&fnames);
+  mutt_hash_free(&fnames);
 
   /* If we didn't just get new mail, update the tables. */
   if (occult)
index 5f753bb256eb55c9e998869fb0877f2b24c4b47f..ac20e5e03856ac97002f90241c6c1333b8db7714 100644 (file)
@@ -701,7 +701,7 @@ int mh_mbox_check(struct Context *ctx, int *index_hint)
 
   /* destroy the file name hash */
 
-  mutt_hash_destroy(&fnames);
+  mutt_hash_free(&fnames);
 
   /* If we didn't just get new mail, update the tables. */
   if (occult)
index f003fc44e82081fa5a6c0f7b9f32e76aed237372..e78821601f8ac89446efa554403c690e5f6d1bde 100644 (file)
@@ -594,9 +594,9 @@ static int reopen_mailbox(struct Context *ctx, int *index_hint)
   old_msgcount = 0;
 
   /* simulate a close */
-  mutt_hash_destroy(&m->id_hash);
-  mutt_hash_destroy(&m->subj_hash);
-  mutt_hash_destroy(&m->label_hash);
+  mutt_hash_free(&m->id_hash);
+  mutt_hash_free(&m->subj_hash);
+  mutt_hash_free(&m->label_hash);
   mutt_clear_threads(ctx);
   FREE(&m->v2r);
   if (m->readonly)
index fad257fa217193c90654f49c02475a2ab9540daa..5fd3551344a568e4537b7461e0b43edf55f230c6 100644 (file)
@@ -58,7 +58,7 @@ void mutt_grouplist_init(void)
  */
 void mutt_grouplist_free(void)
 {
-  mutt_hash_destroy(&Groups);
+  mutt_hash_free(&Groups);
 }
 
 /**
index d28eb7214e8e2089660c5b30c9e909f82996ef55..d512df48df8183fab3828d7cce13b84a68062725 100644 (file)
@@ -253,8 +253,8 @@ static void union_hash_delete(struct Hash *table, union HashKey key, const void
     if ((data == ptr->data || !data) && table->cmp_key(ptr->key, key) == 0)
     {
       *last = ptr->next;
-      if (table->destroy)
-        table->destroy(ptr->type, ptr->data, table->dest_data);
+      if (table->elem_free)
+        table->elem_free(ptr->type, ptr->data, table->hash_data);
       if (table->strdup_keys)
         FREE(&ptr->key.strkey);
       FREE(&ptr);
@@ -317,10 +317,10 @@ struct Hash *mutt_hash_int_new(size_t nelem, int flags)
  * @param fn      Callback function to free Hash Table's resources
  * @param fn_data Data to pass to the callback function
  */
-void mutt_hash_set_destructor(struct Hash *table, hash_destructor_t fn, intptr_t fn_data)
+void mutt_hash_set_destructor(struct Hash *table, hashelem_free_t fn, intptr_t fn_data)
 {
-  table->destroy = fn;
-  table->dest_data = fn_data;
+  table->elem_free = fn;
+  table->hash_data = fn_data;
 }
 
 /**
@@ -452,10 +452,10 @@ void mutt_hash_int_delete(struct Hash *table, unsigned int intkey, const void *d
 }
 
 /**
- * mutt_hash_destroy - Destroy a hash table
+ * mutt_hash_free - elem_free a hash table
  * @param ptr Hash Table to be freed
  */
-void mutt_hash_destroy(struct Hash **ptr)
+void mutt_hash_free(struct Hash **ptr)
 {
   struct Hash *pptr = NULL;
   struct HashElem *elem = NULL, *tmp = NULL;
@@ -470,8 +470,8 @@ void mutt_hash_destroy(struct Hash **ptr)
     {
       tmp = elem;
       elem = elem->next;
-      if (pptr->destroy)
-        pptr->destroy(tmp->type, tmp->data, pptr->dest_data);
+      if (pptr->elem_free)
+        pptr->elem_free(tmp->type, tmp->data, pptr->hash_data);
       if (pptr->strdup_keys)
         FREE(&tmp->key.strkey);
       FREE(&tmp);
index 68e36829595b06d7af63a194748577646c7b40a6..086cce8519cfcf6190f9dcf6db2998218ab08469 100644 (file)
@@ -48,26 +48,26 @@ struct HashElem
 };
 
 /**
- * typedef hash_destructor_t - Prototype for Hash Destructor callback function
+ * typedef hashelem_free_t - Prototype for Hash Destructor callback function
  * @param type Hash Type
  * @param obj  Object to free
  * @param data Data associated with the Hash
  */
-typedef void (*hash_destructor_t)(int type, void *obj, intptr_t data);
+typedef void (*hashelem_free_t)(int type, void *obj, intptr_t data);
 
 /**
  * struct Hash - A Hash Table
  */
 struct Hash
 {
-  size_t nelem;
-  bool strdup_keys : 1; /**< if set, the key->strkey is strdup'ed */
-  bool allow_dups  : 1; /**< if set, duplicate keys are allowed */
-  struct HashElem **table;
-  size_t (*gen_hash)(union HashKey, size_t);
-  int (*cmp_key)(union HashKey, union HashKey);
-  hash_destructor_t destroy;
-  intptr_t dest_data;
+  size_t nelem;            ///< Number of elements in the Hash table
+  bool strdup_keys : 1;    ///< if set, the key->strkey is strdup'ed
+  bool allow_dups  : 1;    ///< if set, duplicate keys are allowed
+  struct HashElem **table; ///< Array of Hash keys
+  size_t (*gen_hash)(union HashKey, size_t);    ///< Function to generate hash id from the key
+  int (*cmp_key)(union HashKey, union HashKey); ///< Function to compare two Hash keys
+  hashelem_free_t elem_free; ///< Function to free a Hash element
+  intptr_t hash_data;        ///< Data to pass to the elem_free() function
 };
 
 /* flags for mutt_hash_new() */
@@ -75,18 +75,18 @@ struct Hash
 #define MUTT_HASH_STRDUP_KEYS (1 << 1) /**< make a copy of the keys */
 #define MUTT_HASH_ALLOW_DUPS  (1 << 2) /**< allow duplicate keys to be inserted */
 
-struct Hash *    mutt_hash_new(size_t nelem, int flags);
 void             mutt_hash_delete(struct Hash *table, const char *strkey, const void *data);
-void             mutt_hash_destroy(struct Hash **ptr);
-void *           mutt_hash_find(const struct Hash *table, const char *strkey);
 struct HashElem *mutt_hash_find_bucket(const struct Hash *table, const char *strkey);
+void *           mutt_hash_find(const struct Hash *table, const char *strkey);
 struct HashElem *mutt_hash_find_elem(const struct Hash *table, const char *strkey);
+void             mutt_hash_free(struct Hash **ptr);
 struct HashElem *mutt_hash_insert(struct Hash *table, const char *strkey, void *data);
-struct Hash *    mutt_hash_int_new(size_t nelem, int flags);
 void             mutt_hash_int_delete(struct Hash *table, unsigned int intkey, const void *data);
 void *           mutt_hash_int_find(const struct Hash *table, unsigned int intkey);
 struct HashElem *mutt_hash_int_insert(struct Hash *table, unsigned int intkey, void *data);
-void             mutt_hash_set_destructor(struct Hash *table, hash_destructor_t fn, intptr_t fn_data);
+struct Hash *    mutt_hash_int_new(size_t nelem, int flags);
+struct Hash *    mutt_hash_new(size_t nelem, int flags);
+void             mutt_hash_set_destructor(struct Hash *table, hashelem_free_t fn, intptr_t fn_data);
 struct HashElem *mutt_hash_typed_insert(struct Hash *table, const char *strkey, int type, void *data);
 
 /**
index 724bd634008b9288d8b101f6eb97b63463cd6a14..ee6fc5ec322c7239110c605e57a9c1ffd039332a 100644 (file)
@@ -299,7 +299,7 @@ cleanup:
   }
   if (HistoryRemoveDups)
     for (hclass = 0; hclass < HC_MAX; hclass++)
-      mutt_hash_destroy(&dup_hashes[hclass]);
+      mutt_hash_free(&dup_hashes[hclass]);
 }
 
 /**
index 8ec31bfddd23caeef1d7f61a4669a4ab05ffb4ef..d3d7591702c4f5d70349eb7b7cba17de810048cb 100644 (file)
@@ -614,7 +614,7 @@ void mutt_clear_threads(struct Context *ctx)
   ctx->tree = NULL;
 
   if (ctx->thread_hash)
-    mutt_hash_destroy(&ctx->thread_hash);
+    mutt_hash_free(&ctx->thread_hash);
 }
 
 /**
diff --git a/mx.c b/mx.c
index 0ec980d22a5361a96c9dbb6bd729bd4a79c38466..7da034ae5ccf617dff0b3d407df4341376f11922 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -416,9 +416,9 @@ void mx_fastclose_mailbox(struct Context *ctx)
   if (m->mx_ops)
     m->mx_ops->mbox_close(m);
 
-  mutt_hash_destroy(&m->subj_hash);
-  mutt_hash_destroy(&m->id_hash);
-  mutt_hash_destroy(&m->label_hash);
+  mutt_hash_free(&m->subj_hash);
+  mutt_hash_free(&m->id_hash);
+  mutt_hash_free(&m->label_hash);
   if (m->emails)
   {
     mutt_clear_threads(ctx);
@@ -1254,13 +1254,13 @@ void mx_update_context(struct Context *ctx)
 
   if (m->subj_hash)
   {
-    mutt_hash_destroy(&m->subj_hash);
+    mutt_hash_free(&m->subj_hash);
   }
   m->subj_hash = NULL;
 
   if (m->id_hash)
   {
-    mutt_hash_destroy(&m->id_hash);
+    mutt_hash_free(&m->id_hash);
   }
   m->id_hash = NULL;
 
index 314a3fa9914f376842073c594ebee4dfea4816d0..c1694b7e274206cee9b56e96baa1a21180e5cf65 100644 (file)
@@ -116,14 +116,6 @@ void nntp_acache_free(struct NntpMboxData *mdata)
   }
 }
 
-/**
- * nntp_hash_destructor_t - Free our hash table data - Implements ::hash_destructor_t
- */
-void nntp_hash_destructor_t(int type, void *obj, intptr_t data)
-{
-  nntp_mdata_free(&obj);
-}
-
 /**
  * nntp_newsrc_close - Unlock and close .newsrc file
  * @param adata NNTP server
@@ -1168,7 +1160,7 @@ struct NntpAccountData *nntp_select_server(struct Mailbox *m, char *server, bool
 
   if (rc < 0)
   {
-    mutt_hash_destroy(&adata->groups_hash);
+    mutt_hash_free(&adata->groups_hash);
     FREE(&adata->groups_list);
     FREE(&adata->newsrc_file);
     FREE(&adata->authenticators);
index dfc2696d1db621343650a21b8fef1bc31016da32..af8b50566db0a2ebfccc73405ff9dce3072f67fb 100644 (file)
@@ -133,6 +133,14 @@ static void nntp_adata_free(void **ptr)
   FREE(ptr);
 }
 
+/**
+ * nntp_hashelem_free - Free our hash table data - Implements ::hashelem_free_t
+ */
+void nntp_hashelem_free(int type, void *obj, intptr_t data)
+{
+  nntp_mdata_free(&obj);
+}
+
 /**
  * nntp_adata_new - Allocate and initialise a new NntpAccountData structure
  * @retval ptr New NntpAccountData
@@ -142,7 +150,7 @@ struct NntpAccountData *nntp_adata_new(struct Connection *conn)
   struct NntpAccountData *adata = mutt_mem_calloc(1, sizeof(struct NntpAccountData));
   adata->conn = conn;
   adata->groups_hash = mutt_hash_new(1009, 0);
-  mutt_hash_set_destructor(adata->groups_hash, nntp_hash_destructor_t, 0);
+  mutt_hash_set_destructor(adata->groups_hash, nntp_hashelem_free, 0);
   adata->groups_max = 16;
   adata->groups_list =
       mutt_mem_malloc(adata->groups_max * sizeof(struct NntpMboxData *));