aboutsummaryrefslogtreecommitdiff
path: root/shell/ash.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-10-07 04:05:15 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-10-07 04:05:15 +0200
commit4c438b5ba4a209a6f47400fe192e9d807c8fe8fd (patch)
tree411b0be2b74255593b302e5bd2b39c72e31e9770 /shell/ash.c
parentf37e1155aabde6bd95d267a8aec347cedccb8bc3 (diff)
downloadbusybox-w32-4c438b5ba4a209a6f47400fe192e9d807c8fe8fd.tar.gz
busybox-w32-4c438b5ba4a209a6f47400fe192e9d807c8fe8fd.tar.bz2
busybox-w32-4c438b5ba4a209a6f47400fe192e9d807c8fe8fd.zip
ash: get rid of two global data variables
function old new delta calcsize 126 147 +21 funcstring_end - 4 +4 sizenodelist 28 24 -4 funcstringsize 4 - -4 funcstring 4 - -4 funcblocksize 4 - -4 nodeckstrdup 48 39 -9 evaltree 828 788 -40 ------------------------------------------------------------------------------ (add/remove: 1/3 grow/shrink: 1/4 up/down: 25/-105) Total: -40 bytes text data bss dec hex filename 943376 916 14292 958584 ea078 busybox_old 943344 916 14284 958544 ea050 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash.c')
-rw-r--r--shell/ash.c99
1 files changed, 48 insertions, 51 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 9a4448f18..4ab2f2077 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -8159,10 +8159,10 @@ commandcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
8159#endif 8159#endif
8160 8160
8161 8161
8162static int funcblocksize; /* size of structures in function */ 8162/*static int funcblocksize; // size of structures in function */
8163static int funcstringsize; /* size of strings in node */ 8163/*static int funcstringsize; // size of strings in node */
8164static void *funcblock; /* block to allocate function from */ 8164static void *funcblock; /* block to allocate function from */
8165static char *funcstring; /* block to allocate strings from */ 8165static char *funcstring_end; /* end of block to allocate strings from */
8166 8166
8167/* flags in argument to evaltree */ 8167/* flags in argument to evaltree */
8168#define EV_EXIT 01 /* exit after evaluating tree */ 8168#define EV_EXIT 01 /* exit after evaluating tree */
@@ -8200,71 +8200,72 @@ static const uint8_t nodesize[N_NUMBER] ALIGN1 = {
8200 [NNOT ] = SHELL_ALIGN(sizeof(struct nnot)), 8200 [NNOT ] = SHELL_ALIGN(sizeof(struct nnot)),
8201}; 8201};
8202 8202
8203static void calcsize(union node *n); 8203static int calcsize(int funcblocksize, union node *n);
8204 8204
8205static void 8205static int
8206sizenodelist(struct nodelist *lp) 8206sizenodelist(int funcblocksize, struct nodelist *lp)
8207{ 8207{
8208 while (lp) { 8208 while (lp) {
8209 funcblocksize += SHELL_ALIGN(sizeof(struct nodelist)); 8209 funcblocksize += SHELL_ALIGN(sizeof(struct nodelist));
8210 calcsize(lp->n); 8210 funcblocksize = calcsize(funcblocksize, lp->n);
8211 lp = lp->next; 8211 lp = lp->next;
8212 } 8212 }
8213 return funcblocksize;
8213} 8214}
8214 8215
8215static void 8216static int
8216calcsize(union node *n) 8217calcsize(int funcblocksize, union node *n)
8217{ 8218{
8218 if (n == NULL) 8219 if (n == NULL)
8219 return; 8220 return funcblocksize;
8220 funcblocksize += nodesize[n->type]; 8221 funcblocksize += nodesize[n->type];
8221 switch (n->type) { 8222 switch (n->type) {
8222 case NCMD: 8223 case NCMD:
8223 calcsize(n->ncmd.redirect); 8224 funcblocksize = calcsize(funcblocksize, n->ncmd.redirect);
8224 calcsize(n->ncmd.args); 8225 funcblocksize = calcsize(funcblocksize, n->ncmd.args);
8225 calcsize(n->ncmd.assign); 8226 funcblocksize = calcsize(funcblocksize, n->ncmd.assign);
8226 break; 8227 break;
8227 case NPIPE: 8228 case NPIPE:
8228 sizenodelist(n->npipe.cmdlist); 8229 funcblocksize = sizenodelist(funcblocksize, n->npipe.cmdlist);
8229 break; 8230 break;
8230 case NREDIR: 8231 case NREDIR:
8231 case NBACKGND: 8232 case NBACKGND:
8232 case NSUBSHELL: 8233 case NSUBSHELL:
8233 calcsize(n->nredir.redirect); 8234 funcblocksize = calcsize(funcblocksize, n->nredir.redirect);
8234 calcsize(n->nredir.n); 8235 funcblocksize = calcsize(funcblocksize, n->nredir.n);
8235 break; 8236 break;
8236 case NAND: 8237 case NAND:
8237 case NOR: 8238 case NOR:
8238 case NSEMI: 8239 case NSEMI:
8239 case NWHILE: 8240 case NWHILE:
8240 case NUNTIL: 8241 case NUNTIL:
8241 calcsize(n->nbinary.ch2); 8242 funcblocksize = calcsize(funcblocksize, n->nbinary.ch2);
8242 calcsize(n->nbinary.ch1); 8243 funcblocksize = calcsize(funcblocksize, n->nbinary.ch1);
8243 break; 8244 break;
8244 case NIF: 8245 case NIF:
8245 calcsize(n->nif.elsepart); 8246 funcblocksize = calcsize(funcblocksize, n->nif.elsepart);
8246 calcsize(n->nif.ifpart); 8247 funcblocksize = calcsize(funcblocksize, n->nif.ifpart);
8247 calcsize(n->nif.test); 8248 funcblocksize = calcsize(funcblocksize, n->nif.test);
8248 break; 8249 break;
8249 case NFOR: 8250 case NFOR:
8250 funcstringsize += strlen(n->nfor.var) + 1; 8251 funcblocksize += strlen(n->nfor.var) + 1; /* was funcstringsize += ... */
8251 calcsize(n->nfor.body); 8252 funcblocksize = calcsize(funcblocksize, n->nfor.body);
8252 calcsize(n->nfor.args); 8253 funcblocksize = calcsize(funcblocksize, n->nfor.args);
8253 break; 8254 break;
8254 case NCASE: 8255 case NCASE:
8255 calcsize(n->ncase.cases); 8256 funcblocksize = calcsize(funcblocksize, n->ncase.cases);
8256 calcsize(n->ncase.expr); 8257 funcblocksize = calcsize(funcblocksize, n->ncase.expr);
8257 break; 8258 break;
8258 case NCLIST: 8259 case NCLIST:
8259 calcsize(n->nclist.body); 8260 funcblocksize = calcsize(funcblocksize, n->nclist.body);
8260 calcsize(n->nclist.pattern); 8261 funcblocksize = calcsize(funcblocksize, n->nclist.pattern);
8261 calcsize(n->nclist.next); 8262 funcblocksize = calcsize(funcblocksize, n->nclist.next);
8262 break; 8263 break;
8263 case NDEFUN: 8264 case NDEFUN:
8264 case NARG: 8265 case NARG:
8265 sizenodelist(n->narg.backquote); 8266 funcblocksize = sizenodelist(funcblocksize, n->narg.backquote);
8266 funcstringsize += strlen(n->narg.text) + 1; 8267 funcblocksize += strlen(n->narg.text) + 1; /* was funcstringsize += ... */
8267 calcsize(n->narg.next); 8268 funcblocksize = calcsize(funcblocksize, n->narg.next);
8268 break; 8269 break;
8269 case NTO: 8270 case NTO:
8270#if ENABLE_ASH_BASH_COMPAT 8271#if ENABLE_ASH_BASH_COMPAT
@@ -8274,33 +8275,31 @@ calcsize(union node *n)
8274 case NFROM: 8275 case NFROM:
8275 case NFROMTO: 8276 case NFROMTO:
8276 case NAPPEND: 8277 case NAPPEND:
8277 calcsize(n->nfile.fname); 8278 funcblocksize = calcsize(funcblocksize, n->nfile.fname);
8278 calcsize(n->nfile.next); 8279 funcblocksize = calcsize(funcblocksize, n->nfile.next);
8279 break; 8280 break;
8280 case NTOFD: 8281 case NTOFD:
8281 case NFROMFD: 8282 case NFROMFD:
8282 calcsize(n->ndup.vname); 8283 funcblocksize = calcsize(funcblocksize, n->ndup.vname);
8283 calcsize(n->ndup.next); 8284 funcblocksize = calcsize(funcblocksize, n->ndup.next);
8284 break; 8285 break;
8285 case NHERE: 8286 case NHERE:
8286 case NXHERE: 8287 case NXHERE:
8287 calcsize(n->nhere.doc); 8288 funcblocksize = calcsize(funcblocksize, n->nhere.doc);
8288 calcsize(n->nhere.next); 8289 funcblocksize = calcsize(funcblocksize, n->nhere.next);
8289 break; 8290 break;
8290 case NNOT: 8291 case NNOT:
8291 calcsize(n->nnot.com); 8292 funcblocksize = calcsize(funcblocksize, n->nnot.com);
8292 break; 8293 break;
8293 }; 8294 };
8295 return funcblocksize;
8294} 8296}
8295 8297
8296static char * 8298static char *
8297nodeckstrdup(char *s) 8299nodeckstrdup(char *s)
8298{ 8300{
8299 char *rtn = funcstring; 8301 funcstring_end -= strlen(s) + 1;
8300 8302 return strcpy(funcstring_end, s);
8301 strcpy(funcstring, s);
8302 funcstring += strlen(s) + 1;
8303 return rtn;
8304} 8303}
8305 8304
8306static union node *copynode(union node *); 8305static union node *copynode(union node *);
@@ -8424,15 +8423,13 @@ copyfunc(union node *n)
8424 struct funcnode *f; 8423 struct funcnode *f;
8425 size_t blocksize; 8424 size_t blocksize;
8426 8425
8427 funcblocksize = offsetof(struct funcnode, n); 8426 /*funcstringsize = 0;*/
8428 funcstringsize = 0; 8427 blocksize = offsetof(struct funcnode, n) + calcsize(0, n);
8429 calcsize(n); 8428 f = ckzalloc(blocksize /* + funcstringsize */);
8430 blocksize = funcblocksize;
8431 f = ckmalloc(blocksize + funcstringsize);
8432 funcblock = (char *) f + offsetof(struct funcnode, n); 8429 funcblock = (char *) f + offsetof(struct funcnode, n);
8433 funcstring = (char *) f + blocksize; 8430 funcstring_end = (char *) f + blocksize;
8434 copynode(n); 8431 copynode(n);
8435 f->count = 0; 8432 /* f->count = 0; - ckzalloc did it */
8436 return f; 8433 return f;
8437} 8434}
8438 8435