From d0243a72d56326af2c5ff7b7b3823dbe57b3bd4c Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 26 Sep 2015 12:54:18 -0400 Subject: Optimize -maxdepth in -depth mode. --- bfs.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'bfs.c') diff --git a/bfs.c b/bfs.c index 5e166de..7669e6d 100644 --- a/bfs.c +++ b/bfs.c @@ -891,7 +891,17 @@ static bftw_action cmdline_callback(struct BFTW *ftwbuf, void *ptr) { state.action = BFTW_SKIP_SUBTREE; } - if (ftwbuf->depth >= cl->mindepth && ftwbuf->depth <= cl->maxdepth) { + // In -depth mode, only handle directories on the BFTW_POST visit + bftw_visit expected_visit = BFTW_PRE; + if ((cl->flags & BFTW_DEPTH) + && ftwbuf->typeflag == BFTW_DIR + && ftwbuf->depth < cl->maxdepth) { + expected_visit = BFTW_POST; + } + + if (ftwbuf->visit == expected_visit + && ftwbuf->depth >= cl->mindepth + && ftwbuf->depth <= cl->maxdepth) { cl->expr->eval(cl->expr, &state); } -- cgit v1.2.3