mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
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>
This commit is contained in:
parent
5fc0585c01
commit
6db5f679a2
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user