Embed the DO_SORT() and the call to skip_duplicates() so I can
understand it better. Then remove the duplicate call to
mutt_buffer_printf().
It seems the sort was delayed until after any initial md entries
without a header were first skipped. However since those aren't
front-loaded by callers, the trade-off is over-complicated, confusing
code for a slightly smaller sort. I don't think it's worth it.
Place the maildir_sort() call before the loop. Remove the last
variable, which is no longer used.
For the checks: "if (! (p && p->h && !p->header_parsed))" p is
guaranteed by the loop. p->header_parsed is only set inside the loop,
so we won't encounter one while looping through. Simplify the check
to just look for p->h.
I added the comment to the sort about reducing seek time after looking
through the commit log: f2eef427.
---
mh.c | 64 ++++++++----------------------------------------------------
1 file changed, 8 insertions(+), 56 deletions(-)
diff --git a/mh.c b/mh.c
index a74e94fb..28244121 100644
--- a/mh.c
+++ b/mh.c
@@ -1101,40 +1101,15 @@ static void mh_sort_natural(CONTEXT *ctx, struct
maildir **md)
*md = maildir_sort(*md, (size_t) -1, md_cmp_path);
}
-#if HAVE_DIRENT_D_INO
-static struct maildir *skip_duplicates(struct maildir *p, struct maildir
**last)
-{
- /*
- * Skip ahead to the next non-duplicate message.
- *
- * p should never reach NULL, because we couldn't have reached this point
unless
- * there was a message that needed to be parsed.
- *
- * the check for p->header_parsed is likely unnecessary since the dupes will
most
- * likely be at the head of the list. but it is present for consistency with
- * the check at the top of the for() loop in maildir_delayed_parsing().
- */
- while (!p->h || p->header_parsed)
- {
- *last = p;
- p = p->next;
- }
- return p;
-}
-#endif
-
/*
* This function does the second parsing pass
*/
static void maildir_delayed_parsing(CONTEXT * ctx, struct maildir **md,
progress_t *progress)
{
- struct maildir *p, *last = NULL;
+ struct maildir *p;
BUFFER *fn = NULL;
int count;
-#if HAVE_DIRENT_D_INO
- int sort = 0;
-#endif
#if USE_HCACHE
header_cache_t *hc = NULL;
void *data;
@@ -1143,46 +1118,26 @@ static void maildir_delayed_parsing(CONTEXT * ctx,
struct maildir **md,
int ret;
#endif
-#if HAVE_DIRENT_D_INO
-#define DO_SORT() \
- do \
- { \
- if (!sort) \
- { \
- muttdbg(4, "maildir: need to sort %s by inode", ctx->path); \
- p = maildir_sort(p, (size_t) -1, md_cmp_inode); \
- if (!last) \
- *md = p; \
- else \
- last->next = p; \
- sort = 1; \
- p = skip_duplicates(p, &last); \
- mutt_buffer_printf(fn, "%s/%s", ctx->path, p->h->path); \
- } \
- } while (0)
-#else
-#define DO_SORT() /* nothing */
-#endif
-
#if USE_HCACHE
hc = mutt_hcache_open(HeaderCache, ctx->path, NULL);
#endif
fn = mutt_buffer_pool_get();
+#if HAVE_DIRENT_D_INO
+ /* If possible, sort by inode number to reduce seek time. */
+ muttdbg(4, "sorting %s by inode", ctx->path);
+ *md = maildir_sort(*md, (size_t) -1, md_cmp_inode);
+#endif
+
for (p = *md, count = 0; p; p = p->next, count++)
{
- if (! (p && p->h && !p->header_parsed))
- {
- last = p;
+ if (!p->h)
continue;
- }
if (!ctx->quiet && progress)
mutt_progress_update(progress, count, -1);
- DO_SORT();
-
mutt_buffer_printf(fn, "%s/%s", ctx->path, p->h->path);
#if USE_HCACHE
@@ -1229,7 +1184,6 @@ static void maildir_delayed_parsing(CONTEXT * ctx, struct
maildir **md,
}
mutt_hcache_free(&data);
#endif
- last = p;
}
#if USE_HCACHE
mutt_hcache_close(hc);
@@ -1237,8 +1191,6 @@ static void maildir_delayed_parsing(CONTEXT * ctx, struct
maildir **md,
mutt_buffer_pool_release(&fn);
-#undef DO_SORT
-
mh_sort_natural(ctx, md);
}
--
2.55.0