ash: simplify "you have mail" code

function                                             old     new   delta
mailtime_hash                                          -       4      +4
redirect                                            1282    1280      -2
mailtime                                              40       -     -40
cmdloop                                              429     378     -51
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 4/-93)             Total: -89 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2015-10-09 15:52:03 +02:00
parent 4700fb5bea
commit 2384162f64
1 changed files with 11 additions and 14 deletions

View File

@ -10029,10 +10029,8 @@ setinputstring(char *string)
#if ENABLE_ASH_MAIL #if ENABLE_ASH_MAIL
#define MAXMBOXES 10 /* Hash of mtimes of mailboxes */
static unsigned mailtime_hash;
/* times of mailboxes */
static time_t mailtime[MAXMBOXES];
/* Set if MAIL or MAILPATH is changed. */ /* Set if MAIL or MAILPATH is changed. */
static smallint mail_var_path_changed; static smallint mail_var_path_changed;
@ -10048,13 +10046,14 @@ chkmail(void)
const char *mpath; const char *mpath;
char *p; char *p;
char *q; char *q;
time_t *mtp; unsigned new_hash;
struct stackmark smark; struct stackmark smark;
struct stat statb; struct stat statb;
setstackmark(&smark); setstackmark(&smark);
mpath = mpathset() ? mpathval() : mailval(); mpath = mpathset() ? mpathval() : mailval();
for (mtp = mailtime; mtp < mailtime + MAXMBOXES; mtp++) { new_hash = 0;
for (;;) {
p = path_advance(&mpath, nullstr); p = path_advance(&mpath, nullstr);
if (p == NULL) if (p == NULL)
break; break;
@ -10068,16 +10067,14 @@ chkmail(void)
#endif #endif
q[-1] = '\0'; /* delete trailing '/' */ q[-1] = '\0'; /* delete trailing '/' */
if (stat(p, &statb) < 0) { if (stat(p, &statb) < 0) {
*mtp = 0;
continue; continue;
} }
if (!mail_var_path_changed && statb.st_mtime != *mtp) { /* Very simplistic "hash": just a sum of all mtimes */
fprintf( new_hash += (unsigned)statb.st_mtime;
stderr, "%s\n", }
pathopt ? pathopt : "you have mail" if (!mail_var_path_changed && mailtime_hash != new_hash) {
); mailtime_hash = new_hash;
} out2str("you have mail\n");
*mtp = statb.st_mtime;
} }
mail_var_path_changed = 0; mail_var_path_changed = 0;
popstackmark(&smark); popstackmark(&smark);