aboutsummaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-05-16 18:36:42 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2013-05-16 18:36:42 +0200
commit6db5f679a21342249e6a6eb06ec70a337bf0d0b0 (patch)
tree12051b2da8daf21492512bad4628edcd046d146a /findutils
parent5fc0585c01a6b87432f344c98eb544e116c2d1d4 (diff)
downloadbusybox-w32-6db5f679a21342249e6a6eb06ec70a337bf0d0b0.tar.gz
busybox-w32-6db5f679a21342249e6a6eb06ec70a337bf0d0b0.tar.bz2
busybox-w32-6db5f679a21342249e6a6eb06ec70a337bf0d0b0.zip
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')
-rw-r--r--findutils/find.c51
1 files changed, 45 insertions, 6 deletions
diff --git a/findutils/find.c b/findutils/find.c
index d4b7c8ec8..af913cc3c 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -815,6 +815,31 @@ static const char* plus_minus_num(const char* str)
815} 815}
816#endif 816#endif
817 817
818/* Say no to GCCism */
819#define USE_NESTED_FUNCTION 0
820
821#if !USE_NESTED_FUNCTION
822struct pp_locals {
823 action*** appp;
824 unsigned cur_group;
825 unsigned cur_action;
826 IF_FEATURE_FIND_NOT( bool invert_flag; )
827};
828static action* alloc_action(struct pp_locals *ppl, int sizeof_struct, action_fp f)
829{
830 action *ap = xzalloc(sizeof_struct);
831 action **app;
832 action ***group = &ppl->appp[ppl->cur_group];
833 *group = app = xrealloc(*group, (ppl->cur_action+2) * sizeof(ppl->appp[0][0]));
834 app[ppl->cur_action++] = ap;
835 app[ppl->cur_action] = NULL;
836 ap->f = f;
837 IF_FEATURE_FIND_NOT( ap->invert = ppl->invert_flag; )
838 IF_FEATURE_FIND_NOT( ppl->invert_flag = 0; )
839 return ap;
840}
841#endif
842
818static action*** parse_params(char **argv) 843static action*** parse_params(char **argv)
819{ 844{
820 enum { 845 enum {
@@ -901,10 +926,18 @@ static action*** parse_params(char **argv)
901 IF_FEATURE_FIND_MAXDEPTH("-mindepth\0""-maxdepth\0") 926 IF_FEATURE_FIND_MAXDEPTH("-mindepth\0""-maxdepth\0")
902 ; 927 ;
903 928
929#if !USE_NESTED_FUNCTION
930 struct pp_locals ppl;
931#define appp (ppl.appp )
932#define cur_group (ppl.cur_group )
933#define cur_action (ppl.cur_action )
934#define invert_flag (ppl.invert_flag)
935#define ALLOC_ACTION(name) (action_##name*)alloc_action(&ppl, sizeof(action_##name), (action_fp) func_##name)
936#else
904 action*** appp; 937 action*** appp;
905 unsigned cur_group = 0; 938 unsigned cur_group;
906 unsigned cur_action = 0; 939 unsigned cur_action;
907 IF_FEATURE_FIND_NOT( bool invert_flag = 0; ) 940 IF_FEATURE_FIND_NOT( bool invert_flag; )
908 941
909 /* This is the only place in busybox where we use nested function. 942 /* This is the only place in busybox where we use nested function.
910 * So far more standard alternatives were bigger. */ 943 * So far more standard alternatives were bigger. */
@@ -913,7 +946,7 @@ static action*** parse_params(char **argv)
913 action* alloc_action(int sizeof_struct, action_fp f) 946 action* alloc_action(int sizeof_struct, action_fp f)
914 { 947 {
915 action *ap; 948 action *ap;
916 appp[cur_group] = xrealloc(appp[cur_group], (cur_action+2) * sizeof(*appp)); 949 appp[cur_group] = xrealloc(appp[cur_group], (cur_action+2) * sizeof(appp[0][0]));
917 appp[cur_group][cur_action++] = ap = xzalloc(sizeof_struct); 950 appp[cur_group][cur_action++] = ap = xzalloc(sizeof_struct);
918 appp[cur_group][cur_action] = NULL; 951 appp[cur_group][cur_action] = NULL;
919 ap->f = f; 952 ap->f = f;
@@ -921,9 +954,12 @@ static action*** parse_params(char **argv)
921 IF_FEATURE_FIND_NOT( invert_flag = 0; ) 954 IF_FEATURE_FIND_NOT( invert_flag = 0; )
922 return ap; 955 return ap;
923 } 956 }
924
925#define ALLOC_ACTION(name) (action_##name*)alloc_action(sizeof(action_##name), (action_fp) func_##name) 957#define ALLOC_ACTION(name) (action_##name*)alloc_action(sizeof(action_##name), (action_fp) func_##name)
958#endif
926 959
960 cur_group = 0;
961 cur_action = 0;
962 IF_FEATURE_FIND_NOT( invert_flag = 0; )
927 appp = xzalloc(2 * sizeof(appp[0])); /* appp[0],[1] == NULL */ 963 appp = xzalloc(2 * sizeof(appp[0])); /* appp[0],[1] == NULL */
928 964
929 while (*argv) { 965 while (*argv) {
@@ -988,7 +1024,7 @@ static action*** parse_params(char **argv)
988 dbg("%d", __LINE__); 1024 dbg("%d", __LINE__);
989 /* start new OR group */ 1025 /* start new OR group */
990 cur_group++; 1026 cur_group++;
991 appp = xrealloc(appp, (cur_group+2) * sizeof(*appp)); 1027 appp = xrealloc(appp, (cur_group+2) * sizeof(appp[0]));
992 /*appp[cur_group] = NULL; - already NULL */ 1028 /*appp[cur_group] = NULL; - already NULL */
993 appp[cur_group+1] = NULL; 1029 appp[cur_group+1] = NULL;
994 cur_action = 0; 1030 cur_action = 0;
@@ -1246,6 +1282,9 @@ static action*** parse_params(char **argv)
1246 dbg("exiting %s", __func__); 1282 dbg("exiting %s", __func__);
1247 return appp; 1283 return appp;
1248#undef ALLOC_ACTION 1284#undef ALLOC_ACTION
1285#undef appp
1286#undef cur_action
1287#undef invert_flag
1249} 1288}
1250 1289
1251int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 1290int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;