]> granicus.if.org Git - neomutt/commitdiff
move Context.{id,subj,label}_hash
authorRichard Russon <rich@flatcap.org>
Sat, 8 Sep 2018 12:28:40 +0000 (13:28 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 9 Sep 2018 15:11:45 +0000 (16:11 +0100)
12 files changed:
context.h
curs_main.c
init.c
mailbox.h
mbox/mbox.c
mutt_header.c
mutt_thread.c
mx.c
nntp/nntp.c
notmuch/mutt_notmuch.c
pop/pop.c
postpone.c

index 713c53887531f5bc75b5fb1dd49a52d9d09ba0ff..2e28ecad83fd1926a2e7bef7f2036f849df1cc16 100644 (file)
--- a/context.h
+++ b/context.h
@@ -39,10 +39,7 @@ struct Context
   struct Pattern *limit_pattern; /**< compiled limit pattern */
   struct Header *last_tag;  /**< last tagged msg. used to link threads */
   struct MuttThread *tree;  /**< top of thread tree */
-  struct Hash *id_hash;     /**< hash table by msg id */
-  struct Hash *subj_hash;   /**< hash table by subject */
   struct Hash *thread_hash; /**< hash table for threading */
-  struct Hash *label_hash;  /**< hash table for x-labels */
   int *v2r;                 /**< mapping from virtual to real msgno */
   int vcount;               /**< the number of virtual messages */
   int tagged;               /**< how many messages are tagged? */
index c9ad06b655b04d9956aa5b6d857744f52cd197e8..cc4d58f7267990095f4f2882a5f6fac0d6473644 100644 (file)
@@ -1331,9 +1331,9 @@ int mutt_index_menu(void)
             mutt_str_strfcpy(buf, STAILQ_FIRST(&CURHDR->env->references)->data,
                              sizeof(buf));
           }
-          if (!Context->id_hash)
-            Context->id_hash = mutt_make_id_hash(Context);
-          hdr = mutt_hash_find(Context->id_hash, buf);
+          if (!Context->mailbox->id_hash)
+            Context->mailbox->id_hash = mutt_make_id_hash(Context);
+          hdr = mutt_hash_find(Context->mailbox->id_hash, buf);
           if (hdr)
           {
             if (hdr->virtual != -1)
@@ -1389,8 +1389,8 @@ int mutt_index_menu(void)
           }
 
           mutt_message(_("Fetching message headers..."));
-          if (!Context->id_hash)
-            Context->id_hash = mutt_make_id_hash(Context);
+          if (!Context->mailbox->id_hash)
+            Context->mailbox->id_hash = mutt_make_id_hash(Context);
           mutt_str_strfcpy(buf, CURHDR->env->message_id, sizeof(buf));
 
           /* trying to find msgid of the root message */
@@ -1399,7 +1399,7 @@ int mutt_index_menu(void)
             struct ListNode *ref = NULL;
             STAILQ_FOREACH(ref, &CURHDR->env->references, entries)
             {
-              if (!mutt_hash_find(Context->id_hash, ref->data))
+              if (!mutt_hash_find(Context->mailbox->id_hash, ref->data))
               {
                 rc2 = nntp_check_msgid(Context, ref->data);
                 if (rc2 < 0)
@@ -1439,7 +1439,7 @@ int mutt_index_menu(void)
             }
 
             /* if the root message was retrieved, move to it */
-            hdr = mutt_hash_find(Context->id_hash, buf);
+            hdr = mutt_hash_find(Context->mailbox->id_hash, buf);
             if (hdr)
               menu->current = hdr->virtual;
 
diff --git a/init.c b/init.c
index f81261ed7c3ead7d2792326adbedf1b83a56ac2a..43ae05fd65b0a25474faefafd8594ac041ccaeb1 100644 (file)
--- a/init.c
+++ b/init.c
@@ -3421,7 +3421,7 @@ int mutt_label_complete(char *buf, size_t buflen, int numtabs)
   char *pt = buf;
   int spaces; /* keep track of the number of leading spaces on the line */
 
-  if (!Context || !Context->label_hash)
+  if (!Context || !Context->mailbox->label_hash)
     return 0;
 
   SKIPWS(buf);
@@ -3437,7 +3437,7 @@ int mutt_label_complete(char *buf, size_t buflen, int numtabs)
     mutt_str_strfcpy(UserTyped, buf, sizeof(UserTyped));
     memset(Matches, 0, MatchesListsize);
     memset(Completed, 0, sizeof(Completed));
-    while ((entry = mutt_hash_walk(Context->label_hash, &state)))
+    while ((entry = mutt_hash_walk(Context->mailbox->label_hash, &state)))
       candidate(UserTyped, entry->key.strkey, Completed, sizeof(Completed));
     matches_ensure_morespace(NumMatched);
     qsort(Matches, NumMatched, sizeof(char *), (sort_t *) mutt_str_strcasecmp);
index c8fa89e5290f7b7d16c96514d857777fbb15e665..f8c10a37a9ad547180629675585afca8fdb1106f 100644 (file)
--- a/mailbox.h
+++ b/mailbox.h
@@ -110,6 +110,10 @@ struct Mailbox
   void *compress_info; /**< compressed mbox module private data */
 #endif
 
+  struct Hash *id_hash;     /**< hash table by msg id */
+  struct Hash *subj_hash;   /**< hash table by subject */
+  struct Hash *label_hash;  /**< hash table for x-labels */
+
   int flags; /**< e.g. #MB_NORMAL */
 };
 
index 7fb1e207f5a6ea733d4e13540ae8f50eabead46b..4d2226f8bea34a3efe86dd2214e8ccf1a57c3f6e 100644 (file)
@@ -796,9 +796,9 @@ static int reopen_mailbox(struct Context *ctx, int *index_hint)
   old_msgcount = 0;
 
   /* simulate a close */
-  mutt_hash_destroy(&ctx->id_hash);
-  mutt_hash_destroy(&ctx->subj_hash);
-  mutt_hash_destroy(&ctx->label_hash);
+  mutt_hash_destroy(&ctx->mailbox->id_hash);
+  mutt_hash_destroy(&ctx->mailbox->subj_hash);
+  mutt_hash_destroy(&ctx->mailbox->label_hash);
   mutt_clear_threads(ctx);
   FREE(&ctx->v2r);
   if (ctx->mailbox->readonly)
@@ -825,8 +825,8 @@ static int reopen_mailbox(struct Context *ctx, int *index_hint)
   ctx->mailbox->msg_unread = 0;
   ctx->mailbox->msg_flagged = 0;
   ctx->mailbox->changed = false;
-  ctx->id_hash = NULL;
-  ctx->subj_hash = NULL;
+  ctx->mailbox->id_hash = NULL;
+  ctx->mailbox->subj_hash = NULL;
   mutt_make_label_hash(ctx);
 
   switch (ctx->mailbox->magic)
index 1bb5e857ebb6d515b7d83711d25600f7430ba991..25ee723c4b1f98c61df7ac25d98d28273354d354 100644 (file)
  */
 static void label_ref_dec(struct Context *ctx, char *label)
 {
-  struct HashElem *elem = mutt_hash_find_elem(ctx->label_hash, label);
+  struct HashElem *elem = mutt_hash_find_elem(ctx->mailbox->label_hash, label);
   if (!elem)
     return;
 
   uintptr_t count = (uintptr_t) elem->data;
   if (count <= 1)
   {
-    mutt_hash_delete(ctx->label_hash, label, NULL);
+    mutt_hash_delete(ctx->mailbox->label_hash, label, NULL);
     return;
   }
 
@@ -73,11 +73,11 @@ static void label_ref_inc(struct Context *ctx, char *label)
 {
   uintptr_t count;
 
-  struct HashElem *elem = mutt_hash_find_elem(ctx->label_hash, label);
+  struct HashElem *elem = mutt_hash_find_elem(ctx->mailbox->label_hash, label);
   if (!elem)
   {
     count = 1;
-    mutt_hash_insert(ctx->label_hash, label, (void *) count);
+    mutt_hash_insert(ctx->mailbox->label_hash, label, (void *) count);
     return;
   }
 
@@ -123,7 +123,7 @@ int mutt_label_message(struct Header *hdr)
   char buf[LONG_STRING], *new = NULL;
   int changed;
 
-  if (!Context || !Context->label_hash)
+  if (!Context || !Context->mailbox->label_hash)
     return 0;
 
   *buf = '\0';
@@ -372,7 +372,7 @@ void mutt_make_label_hash(struct Context *ctx)
   /* 131 is just a rough prime estimate of how many distinct
    * labels someone might have in a mailbox.
    */
-  ctx->label_hash = mutt_hash_create(131, MUTT_HASH_STRDUP_KEYS);
+  ctx->mailbox->label_hash = mutt_hash_create(131, MUTT_HASH_STRDUP_KEYS);
 }
 
 /**
@@ -382,7 +382,7 @@ void mutt_make_label_hash(struct Context *ctx)
  */
 void mutt_label_hash_add(struct Context *ctx, struct Header *hdr)
 {
-  if (!ctx || !ctx->label_hash)
+  if (!ctx || !ctx->mailbox->label_hash)
     return;
   if (hdr->env->x_label)
     label_ref_inc(ctx, hdr->env->x_label);
@@ -395,7 +395,7 @@ void mutt_label_hash_add(struct Context *ctx, struct Header *hdr)
  */
 void mutt_label_hash_remove(struct Context *ctx, struct Header *hdr)
 {
-  if (!ctx || !ctx->label_hash)
+  if (!ctx || !ctx->mailbox->label_hash)
     return;
   if (hdr->env->x_label)
     label_ref_dec(ctx, hdr->env->x_label);
index f324d39349ee6e31ac379a67902f85459fbb0d71..2f3f8f7e856c74c2ec20a7b28fccfe975db0f40e 100644 (file)
@@ -462,7 +462,7 @@ static struct MuttThread *find_subject(struct Context *ctx, struct MuttThread *c
   struct ListNode *np = NULL;
   STAILQ_FOREACH(np, &subjects, entries)
   {
-    for (ptr = mutt_hash_find_bucket(ctx->subj_hash, np->data); ptr; ptr = ptr->next)
+    for (ptr = mutt_hash_find_bucket(ctx->mailbox->subj_hash, np->data); ptr; ptr = ptr->next)
     {
       tmp = ((struct Header *) ptr->data)->thread;
       if (tmp != cur &&                    /* don't match the same message */
@@ -515,8 +515,8 @@ static void pseudo_threads(struct Context *ctx)
   struct MuttThread *tmp = NULL, *cur = NULL, *parent = NULL, *curchild = NULL,
                     *nextchild = NULL;
 
-  if (!ctx->subj_hash)
-    ctx->subj_hash = make_subj_hash(ctx);
+  if (!ctx->mailbox->subj_hash)
+    ctx->mailbox->subj_hash = make_subj_hash(ctx);
 
   while (tree)
   {
diff --git a/mx.c b/mx.c
index ef8aca965e95497f3ad25971518c90c56032005d..69fa1265e84ccff9f95e54bb8eaacd6ba10bf241 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -356,9 +356,9 @@ void mx_fastclose_mailbox(struct Context *ctx)
   if (ctx->mailbox->mx_ops)
     ctx->mailbox->mx_ops->mbox_close(ctx);
 
-  mutt_hash_destroy(&ctx->subj_hash);
-  mutt_hash_destroy(&ctx->id_hash);
-  mutt_hash_destroy(&ctx->label_hash);
+  mutt_hash_destroy(&ctx->mailbox->subj_hash);
+  mutt_hash_destroy(&ctx->mailbox->id_hash);
+  mutt_hash_destroy(&ctx->mailbox->label_hash);
   mutt_clear_threads(ctx);
   for (int i = 0; i < ctx->mailbox->msg_count; i++)
     mutt_header_free(&ctx->mailbox->hdrs[i]);
@@ -844,11 +844,11 @@ void mx_update_tables(struct Context *ctx, bool committing)
                                ctx->mailbox->hdrs[i]->content->hdr_offset);
       }
       /* remove message from the hash tables */
-      if (ctx->subj_hash && ctx->mailbox->hdrs[i]->env->real_subj)
-        mutt_hash_delete(ctx->subj_hash, ctx->mailbox->hdrs[i]->env->real_subj,
+      if (ctx->mailbox->subj_hash && ctx->mailbox->hdrs[i]->env->real_subj)
+        mutt_hash_delete(ctx->mailbox->subj_hash, ctx->mailbox->hdrs[i]->env->real_subj,
                          ctx->mailbox->hdrs[i]);
-      if (ctx->id_hash && ctx->mailbox->hdrs[i]->env->message_id)
-        mutt_hash_delete(ctx->id_hash, ctx->mailbox->hdrs[i]->env->message_id,
+      if (ctx->mailbox->id_hash && ctx->mailbox->hdrs[i]->env->message_id)
+        mutt_hash_delete(ctx->mailbox->id_hash, ctx->mailbox->hdrs[i]->env->message_id,
                          ctx->mailbox->hdrs[i]);
       mutt_label_hash_remove(ctx, ctx->mailbox->hdrs[i]);
       /* The path mx_mbox_check() -> imap_check_mailbox() ->
@@ -1216,10 +1216,10 @@ void mx_update_context(struct Context *ctx, int new_messages)
     {
       struct Header *h2 = NULL;
 
-      if (!ctx->id_hash)
-        ctx->id_hash = mutt_make_id_hash(ctx);
+      if (!ctx->mailbox->id_hash)
+        ctx->mailbox->id_hash = mutt_make_id_hash(ctx);
 
-      h2 = mutt_hash_find(ctx->id_hash, h->env->supersedes);
+      h2 = mutt_hash_find(ctx->mailbox->id_hash, h->env->supersedes);
       if (h2)
       {
         h2->superseded = true;
@@ -1229,10 +1229,10 @@ void mx_update_context(struct Context *ctx, int new_messages)
     }
 
     /* add this message to the hash tables */
-    if (ctx->id_hash && h->env->message_id)
-      mutt_hash_insert(ctx->id_hash, h->env->message_id, h);
-    if (ctx->subj_hash && h->env->real_subj)
-      mutt_hash_insert(ctx->subj_hash, h->env->real_subj, h);
+    if (ctx->mailbox->id_hash && h->env->message_id)
+      mutt_hash_insert(ctx->mailbox->id_hash, h->env->message_id, h);
+    if (ctx->mailbox->subj_hash && h->env->real_subj)
+      mutt_hash_insert(ctx->mailbox->subj_hash, h->env->real_subj, h);
     mutt_label_hash_add(ctx, h);
 
     if (Score)
index e24487bd7088c850119c935857df0fd4e0662e1e..6e8a28cfbffa6d69442216ce415b590125e64afb 100644 (file)
@@ -1729,18 +1729,18 @@ static int nntp_msg_open(struct Context *ctx, struct Message *msg, int msgno)
 
   /* replace envelope with new one
    * hash elements must be updated because pointers will be changed */
-  if (ctx->id_hash && hdr->env->message_id)
-    mutt_hash_delete(ctx->id_hash, hdr->env->message_id, hdr);
-  if (ctx->subj_hash && hdr->env->real_subj)
-    mutt_hash_delete(ctx->subj_hash, hdr->env->real_subj, hdr);
+  if (ctx->mailbox->id_hash && hdr->env->message_id)
+    mutt_hash_delete(ctx->mailbox->id_hash, hdr->env->message_id, hdr);
+  if (ctx->mailbox->subj_hash && hdr->env->real_subj)
+    mutt_hash_delete(ctx->mailbox->subj_hash, hdr->env->real_subj, hdr);
 
   mutt_env_free(&hdr->env);
   hdr->env = mutt_rfc822_read_header(msg->fp, hdr, false, false);
 
-  if (ctx->id_hash && hdr->env->message_id)
-    mutt_hash_insert(ctx->id_hash, hdr->env->message_id, hdr);
-  if (ctx->subj_hash && hdr->env->real_subj)
-    mutt_hash_insert(ctx->subj_hash, hdr->env->real_subj, hdr);
+  if (ctx->mailbox->id_hash && hdr->env->message_id)
+    mutt_hash_insert(ctx->mailbox->id_hash, hdr->env->message_id, hdr);
+  if (ctx->mailbox->subj_hash && hdr->env->real_subj)
+    mutt_hash_insert(ctx->mailbox->subj_hash, hdr->env->real_subj, hdr);
 
   /* fix content length */
   fseek(msg->fp, 0, SEEK_END);
@@ -2074,10 +2074,10 @@ static int check_mailbox(struct Context *ctx)
   /* some headers were removed, context must be updated */
   if (ret == MUTT_REOPENED)
   {
-    if (ctx->subj_hash)
-      mutt_hash_destroy(&ctx->subj_hash);
-    if (ctx->id_hash)
-      mutt_hash_destroy(&ctx->id_hash);
+    if (ctx->mailbox->subj_hash)
+      mutt_hash_destroy(&ctx->mailbox->subj_hash);
+    if (ctx->mailbox->id_hash)
+      mutt_hash_destroy(&ctx->mailbox->id_hash);
     mutt_clear_threads(ctx);
 
     ctx->vcount = 0;
@@ -2086,8 +2086,8 @@ static int check_mailbox(struct Context *ctx)
     ctx->mailbox->msg_unread = 0;
     ctx->mailbox->msg_flagged = 0;
     ctx->mailbox->changed = false;
-    ctx->id_hash = NULL;
-    ctx->subj_hash = NULL;
+    ctx->mailbox->id_hash = NULL;
+    ctx->mailbox->subj_hash = NULL;
     mx_update_context(ctx, ctx->mailbox->msg_count);
   }
 
index 8f903d32db34313920dd86d4c43202bca6b57eab..bbda66f16ddc9ea67df66b79b3f09f0c9efd070c 100644 (file)
@@ -1102,18 +1102,18 @@ static struct Header *get_mutt_header(struct Context *ctx, notmuch_message_t *ms
 
   mutt_debug(2, "nm: neomutt header, id='%s'\n", id);
 
-  if (!ctx->id_hash)
+  if (!ctx->mailbox->id_hash)
   {
     mutt_debug(2, "nm: init hash\n");
-    ctx->id_hash = mutt_make_id_hash(ctx);
-    if (!ctx->id_hash)
+    ctx->mailbox->id_hash = mutt_make_id_hash(ctx);
+    if (!ctx->mailbox->id_hash)
       return NULL;
   }
 
   mid = nm2mutt_message_id(id);
   mutt_debug(2, "nm: neomutt id='%s'\n", mid);
 
-  h = mutt_hash_find(ctx->id_hash, mid);
+  h = mutt_hash_find(ctx->mailbox->id_hash, mid);
   FREE(&mid);
   return h;
 }
index 392b028e619787df54765c134ddd1f487b2a9bca..0e3cac14cd74b14bf1db664fe93210d857c21ebe 100644 (file)
--- a/pop/pop.c
+++ b/pop/pop.c
@@ -720,13 +720,13 @@ static int pop_msg_open(struct Context *ctx, struct Message *msg, int msgno)
   uidl = h->data;
 
   /* we replace envelop, key in subj_hash has to be updated as well */
-  if (ctx->subj_hash && h->env->real_subj)
-    mutt_hash_delete(ctx->subj_hash, h->env->real_subj, h);
+  if (ctx->mailbox->subj_hash && h->env->real_subj)
+    mutt_hash_delete(ctx->mailbox->subj_hash, h->env->real_subj, h);
   mutt_label_hash_remove(ctx, h);
   mutt_env_free(&h->env);
   h->env = mutt_rfc822_read_header(msg->fp, h, false, false);
-  if (ctx->subj_hash && h->env->real_subj)
-    mutt_hash_insert(ctx->subj_hash, h->env->real_subj, h);
+  if (ctx->mailbox->subj_hash && h->env->real_subj)
+    mutt_hash_insert(ctx->mailbox->subj_hash, h->env->real_subj, h);
   mutt_label_hash_add(ctx, h);
 
   h->data = uidl;
index 45b07d21707dc80ba380df2e08b81b79a78ed21b..1b90741321d81c3a9f53a8d7dfdb15d6025a035a 100644 (file)
@@ -348,9 +348,9 @@ int mutt_get_postponed(struct Context *ctx, struct Header *hdr,
         /* if a mailbox is currently open, look to see if the original message
            the user attempted to reply to is in this mailbox */
         p = mutt_str_skip_email_wsp(np->data + 18);
-        if (!ctx->id_hash)
-          ctx->id_hash = mutt_make_id_hash(ctx);
-        *cur = mutt_hash_find(ctx->id_hash, p);
+        if (!ctx->mailbox->id_hash)
+          ctx->mailbox->id_hash = mutt_make_id_hash(ctx);
+        *cur = mutt_hash_find(ctx->mailbox->id_hash, p);
       }
       if (*cur)
         code |= SEND_REPLY;