Hi Kevin and all,

On Wed, Feb 04, 2026 at 01:04:20PM +0800, Kevin J. McCarthy wrote:
> I'm sure I don't need to ask for feedback, but this is a tradeoff of a
> couple stat calls for correct behavior in some less common situations.
> Thoughts?

Functionally I agree with the change. But the repeated function calls
have a look of inefficiency, although I'm aware that this is nit.

Out of curiosity I rewrote it to iterate over the three subdirectory
names and compared the difference in size of the binaries. In this
case it apparently is dominated by (debug) symbols and not hitting a
threshold for reduced size of a fully stripped binary on my system.

So having done this anyway, I propose an optimization utilizing the
uniform length of the names. (Further compacting the code saves more
space but degrades readability of the logic.)


diff --git a/mh.c b/mh.c
index b048a791..2b7c69a8 100644
--- a/mh.c
+++ b/mh.c
@@ -2747,24 +2747,22 @@ int mx_is_maildir (const char *path)
   BUFFER *tmp = NULL;
   struct stat st;
   int rc = 0;
+  char * path_comp_ptr;
+  int i;
 
   tmp = mutt_buffer_pool_get ();
 
-  mutt_buffer_printf (tmp, "%s/cur", path);
-  if (stat (mutt_b2s (tmp), &st) != 0 || !S_ISDIR (st.st_mode))
-    goto out;
-
-  mutt_buffer_printf (tmp, "%s/new", path);
-  if (stat (mutt_b2s (tmp), &st) != 0 || !S_ISDIR (st.st_mode))
-    goto out;
-
-  mutt_buffer_printf (tmp, "%s/tmp", path);
-  if (stat (mutt_b2s (tmp), &st) != 0 || !S_ISDIR (st.st_mode))
-    goto out;
-
-  rc = 1;
+  path_comp_ptr = tmp->data + mutt_buffer_printf (tmp, "%s/cur", path) - 3;
+  for (i = 0; stat (mutt_b2s (tmp), &st) == 0 && S_ISDIR (st.st_mode); i++)
+  {
+    if (i >= 2)
+    {
+      rc = 1;
+      break;
+    }
+    memcpy (path_comp_ptr, i == 0 ? "tmp" : "new", 3);
+  }
 
-out:
   mutt_buffer_pool_release (&tmp);
   return rc;
 }



Kind regards,
   Gero

Reply via email to