aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/busybox/busybox/find-get-rid-of-nested-functions.patch
blob: d66ef79cf04792fc7294063b1e336826b79461fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
Upstream-Status: Accepted

commit 6db5f679a21342249e6a6eb06ec70a337bf0d0b0
Author: Denys Vlasenko <vda.linux@googlemail.com>
Date:   Thu May 16 18:36:42 2013 +0200

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>

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;