From: Richard Russon Date: Sat, 8 Sep 2018 12:28:40 +0000 (+0100) Subject: move Context.{id,subj,label}_hash X-Git-Tag: 2019-10-25~657^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=089752d45e790413109218931c36664c50604ca0;p=neomutt move Context.{id,subj,label}_hash --- diff --git a/context.h b/context.h index 713c53887..2e28ecad8 100644 --- 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? */ diff --git a/curs_main.c b/curs_main.c index c9ad06b65..cc4d58f72 100644 --- a/curs_main.c +++ b/curs_main.c @@ -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 f81261ed7..43ae05fd6 100644 --- 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); diff --git a/mailbox.h b/mailbox.h index c8fa89e52..f8c10a37a 100644 --- 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 */ }; diff --git a/mbox/mbox.c b/mbox/mbox.c index 7fb1e207f..4d2226f8b 100644 --- a/mbox/mbox.c +++ b/mbox/mbox.c @@ -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) diff --git a/mutt_header.c b/mutt_header.c index 1bb5e857e..25ee723c4 100644 --- a/mutt_header.c +++ b/mutt_header.c @@ -49,14 +49,14 @@ */ 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); diff --git a/mutt_thread.c b/mutt_thread.c index f324d3934..2f3f8f7e8 100644 --- a/mutt_thread.c +++ b/mutt_thread.c @@ -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 ef8aca965..69fa1265e 100644 --- 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) diff --git a/nntp/nntp.c b/nntp/nntp.c index e24487bd7..6e8a28cfb 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -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); } diff --git a/notmuch/mutt_notmuch.c b/notmuch/mutt_notmuch.c index 8f903d32d..bbda66f16 100644 --- a/notmuch/mutt_notmuch.c +++ b/notmuch/mutt_notmuch.c @@ -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; } diff --git a/pop/pop.c b/pop/pop.c index 392b028e6..0e3cac14c 100644 --- 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; diff --git a/postpone.c b/postpone.c index 45b07d217..1b9074132 100644 --- a/postpone.c +++ b/postpone.c @@ -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;