[git commit] ash: get rid of separate mail_var_path_changed flag variable

Denys Vlasenko vda.linux at googlemail.com
Mon Apr 3 13:01:00 UTC 2023


commit: https://git.busybox.net/busybox/commit/?id=94780e3e8e926e7e9f384c4b70310b3e7e79abce
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

We can just clear mailtime_hash to zero and have the same effect.

function                                             old     new   delta
changemail                                             8      11      +3
mail_var_path_changed                                  1       -      -1
cmdloop                                              398     382     -16
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 3/-17)             Total: -14 bytes
   text	   data	    bss	    dec	    hex	filename
1054786	    559	   5020	1060365	 102e0d	busybox_old
1054773	    559	   5020	1060352	 102e00	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 shell/ash.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/shell/ash.c b/shell/ash.c
index f057b8963..bd3afc0c8 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -2110,10 +2110,7 @@ change_lc_ctype(const char *value)
 }
 #endif
 #if ENABLE_ASH_MAIL
-static void chkmail(void);
 static void changemail(const char *var_value) FAST_FUNC;
-#else
-# define chkmail()  ((void)0)
 #endif
 static void changepath(const char *) FAST_FUNC;
 #if ENABLE_ASH_RANDOM_SUPPORT
@@ -11258,13 +11255,12 @@ setinputstring(char *string)
 #if ENABLE_ASH_MAIL
 
 /* Hash of mtimes of mailboxes */
+/* Cleared to 0 if MAIL or MAILPATH is changed */
 static unsigned mailtime_hash;
-/* Set if MAIL or MAILPATH is changed. */
-static smallint mail_var_path_changed;
 
 /*
  * Print appropriate message(s) if mail has arrived.
- * If mail_var_path_changed is set,
+ * If mailtime_hash is zero,
  * then the value of MAIL has changed,
  * so we just update the hash value.
  */
@@ -11303,21 +11299,24 @@ chkmail(void)
 		/* Very simplistic "hash": just a sum of all mtimes */
 		new_hash += (unsigned)statb.st_mtime;
 	}
-	if (!mail_var_path_changed && mailtime_hash != new_hash) {
+	if (mailtime_hash != new_hash) {
 		if (mailtime_hash != 0)
 			out2str("you have mail\n");
+		mailtime_hash = new_hash;
 	}
-	mailtime_hash = new_hash;
-	mail_var_path_changed = 0;
 	popstackmark(&smark);
 }
 
 static void FAST_FUNC
 changemail(const char *val UNUSED_PARAM)
 {
-	mail_var_path_changed = 1;
+	mailtime_hash = 0;
 }
 
+#else
+
+# define chkmail()  ((void)0)
+
 #endif /* ASH_MAIL */
 
 


More information about the busybox-cvs mailing list