diff options
author | Denys Vlasenko | 2021-10-10 15:18:12 +0200 |
---|---|---|
committer | Denys Vlasenko | 2021-10-10 15:18:12 +0200 |
commit | d8e39b5917a5dc9c11ecf5714b8c2e1037a9838d (patch) | |
tree | dc1291cfffb1408071dc2aa9f8eff978d2dab670 /findutils | |
parent | d3dbf4ac05e969b6648faea282df6dec7051e315 (diff) | |
download | busybox-d8e39b5917a5dc9c11ecf5714b8c2e1037a9838d.zip busybox-d8e39b5917a5dc9c11ecf5714b8c2e1037a9838d.tar.gz |
find: code shrink -{m,a,c}{time,min}
function old new delta
time_cmp - 181 +181
func_mmin 171 31 -140
func_mtime 180 34 -146
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 181/-286) Total: -105 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'findutils')
-rw-r--r-- | findutils/find.c | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/findutils/find.c b/findutils/find.c index 9feb44b..fdc5c15 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -440,8 +440,8 @@ IF_FEATURE_FIND_PRINT0( ACTS(print0)) IF_FEATURE_FIND_TYPE( ACTS(type, int type_mask;)) IF_FEATURE_FIND_EXECUTABLE(ACTS(executable)) IF_FEATURE_FIND_PERM( ACTS(perm, char perm_char; mode_t perm_mask;)) -IF_FEATURE_FIND_MTIME( ACTS(mtime, char time_type; char mtime_char; unsigned mtime_days;)) -IF_FEATURE_FIND_MMIN( ACTS(mmin, char time_type; char mmin_char; unsigned mmin_mins;)) +IF_FEATURE_FIND_MTIME( ACTS(mtime, unsigned char time_type; unsigned char mtime_char; unsigned mtime_days;)) +IF_FEATURE_FIND_MMIN( ACTS(mmin, unsigned char time_type; unsigned char mmin_char; unsigned mmin_mins;)) IF_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;)) IF_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;)) IF_FEATURE_FIND_USER( ACTS(user, uid_t uid;)) @@ -670,14 +670,29 @@ ACTF(perm) || ENABLE_FEATURE_FIND_CTIME \ || ENABLE_FEATURE_FIND_MMIN \ || ENABLE_FEATURE_FIND_MTIME -static int time_cmp(time_t ftime, char time_char, time_t secs, time_t delta) +static int time_cmp(const struct stat *statbuf, unsigned type_and_char, time_t N_from_user, unsigned unit) { - time_t file_age = time(NULL) - ftime; - switch (time_char) { - case '+': return file_age >= secs + delta; - case '-': return file_age < secs; + time_t ftime, file_age; + + ftime = statbuf->st_mtime; +# if ENABLE_FEATURE_FIND_ATIME || ENABLE_FEATURE_FIND_CTIME +# if ENABLE_FEATURE_FIND_ATIME + if ((type_and_char >> 8) == 'a') + ftime = statbuf->st_atime; +# endif +# if ENABLE_FEATURE_FIND_CTIME + if ((type_and_char >> 8) == 'c') + ftime = statbuf->st_ctime; +# endif + type_and_char &= 0xff; +# endif + file_age = time(NULL) - ftime; + N_from_user *= unit; + switch (type_and_char) { + case '+': return file_age >= N_from_user + unit; + case '-': return file_age < N_from_user; /* just numeric time */ - default: return file_age >= secs && file_age < secs + delta; + default: return file_age >= N_from_user && file_age < N_from_user + unit; } } #endif @@ -685,33 +700,23 @@ static int time_cmp(time_t ftime, char time_char, time_t secs, time_t delta) #if ENABLE_FEATURE_FIND_MTIME ACTF(mtime) { - time_t t = statbuf->st_mtime; -# if ENABLE_FEATURE_FIND_ATIME - if (ap->time_type == 'a') - t = statbuf->st_atime; + return time_cmp(statbuf, +# if ENABLE_FEATURE_FIND_ATIME || ENABLE_FEATURE_FIND_CTIME + (ap->time_type << 8) | # endif -# if ENABLE_FEATURE_FIND_CTIME - if (ap->time_type == 'c') - t = statbuf->st_ctime; -# endif - return time_cmp(t, ap->mtime_char, - ap->mtime_days * 24*60*60, 24*60*60); + ap->mtime_char, + ap->mtime_days, 24*60*60); } #endif #if ENABLE_FEATURE_FIND_MMIN ACTF(mmin) { - time_t t = statbuf->st_mtime; -# if ENABLE_FEATURE_FIND_AMIN - if (ap->time_type == 'a') - t = statbuf->st_atime; -# endif -# if ENABLE_FEATURE_FIND_CMIN - if (ap->time_type == 'c') - t = statbuf->st_ctime; + return time_cmp(statbuf, +# if ENABLE_FEATURE_FIND_ATIME || ENABLE_FEATURE_FIND_CTIME + (ap->time_type << 8) | # endif - return time_cmp(t, ap->mmin_char, - ap->mmin_mins * 60, 60); + ap->mmin_char, + ap->mmin_mins, 60); } #endif #if ENABLE_FEATURE_FIND_NEWER |