aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-09-27 01:51:47 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-09-27 01:51:47 +0200
commit6c750f15180ba51ef37c6cfa381b52e6b05d55aa (patch)
tree8ac8783178491ebd1a57b53ac03829ab717687bd
parent48f116198d53697d59d03f4e0ff6cd8c04e79660 (diff)
downloadbusybox-w32-6c750f15180ba51ef37c6cfa381b52e6b05d55aa.tar.gz
busybox-w32-6c750f15180ba51ef37c6cfa381b52e6b05d55aa.tar.bz2
busybox-w32-6c750f15180ba51ef37c6cfa381b52e6b05d55aa.zip
find: do not recurse into directories with depth == --maxdepth
This may avoid many, many unnecessary stat() calls function old new delta fileAction 718 758 +40 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--findutils/find.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 47c86be15..bd92e2281 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -65,7 +65,7 @@
65IF_FEATURE_FIND_XDEV(static dev_t *xdev_dev;) 65IF_FEATURE_FIND_XDEV(static dev_t *xdev_dev;)
66IF_FEATURE_FIND_XDEV(static int xdev_count;) 66IF_FEATURE_FIND_XDEV(static int xdev_count;)
67 67
68typedef int (*action_fp)(const char *fileName, struct stat *statbuf, void *) FAST_FUNC; 68typedef int (*action_fp)(const char *fileName, const struct stat *statbuf, void *) FAST_FUNC;
69 69
70typedef struct { 70typedef struct {
71 action_fp f; 71 action_fp f;
@@ -77,7 +77,7 @@ typedef struct {
77#define ACTS(name, ...) typedef struct { action a; __VA_ARGS__ } action_##name; 77#define ACTS(name, ...) typedef struct { action a; __VA_ARGS__ } action_##name;
78#define ACTF(name) \ 78#define ACTF(name) \
79 static int FAST_FUNC func_##name(const char *fileName UNUSED_PARAM, \ 79 static int FAST_FUNC func_##name(const char *fileName UNUSED_PARAM, \
80 struct stat *statbuf UNUSED_PARAM, \ 80 const struct stat *statbuf UNUSED_PARAM, \
81 action_##name* ap UNUSED_PARAM) 81 action_##name* ap UNUSED_PARAM)
82 82
83 ACTS(print) 83 ACTS(print)
@@ -139,7 +139,7 @@ static char* subst(const char *src, unsigned count, const char* filename)
139 * bit 0=1: matched successfully (TRUE) 139 * bit 0=1: matched successfully (TRUE)
140 */ 140 */
141 141
142static int exec_actions(action ***appp, const char *fileName, struct stat *statbuf) 142static int exec_actions(action ***appp, const char *fileName, const struct stat *statbuf)
143{ 143{
144 int cur_group; 144 int cur_group;
145 int cur_action; 145 int cur_action;
@@ -392,26 +392,34 @@ static int FAST_FUNC fileAction(const char *fileName,
392 392
393 if (depth < minmaxdepth[0]) return TRUE; 393 if (depth < minmaxdepth[0]) return TRUE;
394 if (depth > minmaxdepth[1]) return SKIP; 394 if (depth > minmaxdepth[1]) return SKIP;
395#undef minmaxdepth
396#endif 395#endif
397 396
398#if ENABLE_FEATURE_FIND_XDEV 397#if ENABLE_FEATURE_FIND_XDEV
399 if (S_ISDIR(statbuf->st_mode) && xdev_count) { 398 if (S_ISDIR(statbuf->st_mode)) {
400 for (i = 0; i < xdev_count; i++) { 399 if (xdev_count) {
401 if (xdev_dev[i] == statbuf->st_dev) 400 for (i = 0; i < xdev_count; i++) {
402 break; 401 if (xdev_dev[i] == statbuf->st_dev)
403 } 402 goto found;
404 if (i == xdev_count) 403 }
405 return SKIP; 404 return SKIP;
405 found: ;
406 }
406 } 407 }
407#endif 408#endif
408 i = exec_actions(actions, fileName, statbuf); 409 i = exec_actions(actions, fileName, statbuf);
409 /* Had no explicit -print[0] or -exec? then print */ 410 /* Had no explicit -print[0] or -exec? then print */
410 if ((i & TRUE) && need_print) 411 if ((i & TRUE) && need_print)
411 puts(fileName); 412 puts(fileName);
413
414#if ENABLE_FEATURE_FIND_MAXDEPTH
415 if (S_ISDIR(statbuf->st_mode))
416 if (depth == minmaxdepth[1])
417 return SKIP;
418#endif
412 /* Cannot return 0: our caller, recursive_action(), 419 /* Cannot return 0: our caller, recursive_action(),
413 * will perror() and skip dirs (if called on dir) */ 420 * will perror() and skip dirs (if called on dir) */
414 return (i & SKIP) ? SKIP : TRUE; 421 return (i & SKIP) ? SKIP : TRUE;
422#undef minmaxdepth
415} 423}
416 424
417 425