diff options
author | Denys Vlasenko | 2013-05-16 18:36:42 +0200 |
---|---|---|
committer | Denys Vlasenko | 2013-05-16 18:36:42 +0200 |
commit | 6db5f679a21342249e6a6eb06ec70a337bf0d0b0 (patch) | |
tree | 12051b2da8daf21492512bad4628edcd046d146a /findutils/find.c | |
parent | 5fc0585c01a6b87432f344c98eb544e116c2d1d4 (diff) | |
download | busybox-6db5f679a21342249e6a6eb06ec70a337bf0d0b0.zip busybox-6db5f679a21342249e6a6eb06ec70a337bf0d0b0.tar.gz |
find:: get rid of nested function (it's a gcc-ism)
function old new delta
alloc_action - 80 +80
parse_params 1459 1445 -14
static.alloc_action 98 - -98
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/1 up/down: 80/-112) Total: -32 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'findutils/find.c')
-rw-r--r-- | findutils/find.c | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/findutils/find.c b/findutils/find.c index d4b7c8e..af913cc 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -815,6 +815,31 @@ static const char* plus_minus_num(const char* str) } #endif +/* Say no to GCCism */ +#define USE_NESTED_FUNCTION 0 + +#if !USE_NESTED_FUNCTION +struct pp_locals { + action*** appp; + unsigned cur_group; + unsigned cur_action; + IF_FEATURE_FIND_NOT( bool invert_flag; ) +}; +static action* alloc_action(struct pp_locals *ppl, int sizeof_struct, action_fp f) +{ + action *ap = xzalloc(sizeof_struct); + action **app; + action ***group = &ppl->appp[ppl->cur_group]; + *group = app = xrealloc(*group, (ppl->cur_action+2) * sizeof(ppl->appp[0][0])); + app[ppl->cur_action++] = ap; + app[ppl->cur_action] = NULL; + ap->f = f; + IF_FEATURE_FIND_NOT( ap->invert = ppl->invert_flag; ) + IF_FEATURE_FIND_NOT( ppl->invert_flag = 0; ) + return ap; +} +#endif + static action*** parse_params(char **argv) { enum { @@ -901,10 +926,18 @@ static action*** parse_params(char **argv) IF_FEATURE_FIND_MAXDEPTH("-mindepth\0""-maxdepth\0") ; +#if !USE_NESTED_FUNCTION + struct pp_locals ppl; +#define appp (ppl.appp ) +#define cur_group (ppl.cur_group ) +#define cur_action (ppl.cur_action ) +#define invert_flag (ppl.invert_flag) +#define ALLOC_ACTION(name) (action_##name*)alloc_action(&ppl, sizeof(action_##name), (action_fp) func_##name) +#else action*** appp; - unsigned cur_group = 0; - unsigned cur_action = 0; - IF_FEATURE_FIND_NOT( bool invert_flag = 0; ) + unsigned cur_group; + unsigned cur_action; + IF_FEATURE_FIND_NOT( bool invert_flag; ) /* This is the only place in busybox where we use nested function. * So far more standard alternatives were bigger. */ @@ -913,7 +946,7 @@ static action*** parse_params(char **argv) action* alloc_action(int sizeof_struct, action_fp f) { action *ap; - appp[cur_group] = xrealloc(appp[cur_group], (cur_action+2) * sizeof(*appp)); + appp[cur_group] = xrealloc(appp[cur_group], (cur_action+2) * sizeof(appp[0][0])); appp[cur_group][cur_action++] = ap = xzalloc(sizeof_struct); appp[cur_group][cur_action] = NULL; ap->f = f; @@ -921,9 +954,12 @@ static action*** parse_params(char **argv) IF_FEATURE_FIND_NOT( invert_flag = 0; ) return ap; } - #define ALLOC_ACTION(name) (action_##name*)alloc_action(sizeof(action_##name), (action_fp) func_##name) +#endif + cur_group = 0; + cur_action = 0; + IF_FEATURE_FIND_NOT( invert_flag = 0; ) appp = xzalloc(2 * sizeof(appp[0])); /* appp[0],[1] == NULL */ while (*argv) { @@ -988,7 +1024,7 @@ static action*** parse_params(char **argv) dbg("%d", __LINE__); /* start new OR group */ cur_group++; - appp = xrealloc(appp, (cur_group+2) * sizeof(*appp)); + appp = xrealloc(appp, (cur_group+2) * sizeof(appp[0])); /*appp[cur_group] = NULL; - already NULL */ appp[cur_group+1] = NULL; cur_action = 0; @@ -1246,6 +1282,9 @@ static action*** parse_params(char **argv) dbg("exiting %s", __func__); return appp; #undef ALLOC_ACTION +#undef appp +#undef cur_action +#undef invert_flag } int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |