diff options
author | Ron Yorston <rmy@pobox.com> | 2022-05-20 12:50:34 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2022-05-20 12:50:34 +0100 |
commit | bd584ee9d76ca4353fcd5af87a4f413316d3a552 (patch) | |
tree | b2803fbe4b92f680ee834f3fdcc702e11dc3bb82 /shell | |
parent | eca8fe9c69bd15760ba5206f9ddd7bbf825bcda1 (diff) | |
download | busybox-w32-bd584ee9d76ca4353fcd5af87a4f413316d3a552.tar.gz busybox-w32-bd584ee9d76ca4353fcd5af87a4f413316d3a552.tar.bz2 busybox-w32-bd584ee9d76ca4353fcd5af87a4f413316d3a552.zip |
ash: code shrink
Commit 6f8b2f450 (ash: forkshell code shrink) noted that certain
global variables were being passed around in the forkshell structure
unnecessarily.
In fact, since the variables are global there's no need to pass
them to the *_size()/*_copy() functions at all. This only saves
32 bytes of bloat (the compiler got there ahead of us) but it does
make the code tidier.
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 96 |
1 files changed, 50 insertions, 46 deletions
diff --git a/shell/ash.c b/shell/ash.c index ab2b0628f..b34ed67a7 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -16253,24 +16253,24 @@ tblentry_copy(struct tblentry *tep) | |||
16253 | } | 16253 | } |
16254 | 16254 | ||
16255 | static struct datasize | 16255 | static struct datasize |
16256 | cmdtable_size(struct datasize ds, struct tblentry **cmdtablep) | 16256 | cmdtable_size(struct datasize ds) |
16257 | { | 16257 | { |
16258 | int i; | 16258 | int i; |
16259 | ds.funcblocksize += sizeof(struct tblentry *)*CMDTABLESIZE; | 16259 | ds.funcblocksize += sizeof(struct tblentry *)*CMDTABLESIZE; |
16260 | for (i = 0; i < CMDTABLESIZE; i++) | 16260 | for (i = 0; i < CMDTABLESIZE; i++) |
16261 | ds = tblentry_size(ds, cmdtablep[i]); | 16261 | ds = tblentry_size(ds, cmdtable[i]); |
16262 | return ds; | 16262 | return ds; |
16263 | } | 16263 | } |
16264 | 16264 | ||
16265 | static struct tblentry ** | 16265 | static struct tblentry ** |
16266 | cmdtable_copy(struct tblentry **cmdtablep) | 16266 | cmdtable_copy(void) |
16267 | { | 16267 | { |
16268 | struct tblentry **new = funcblock; | 16268 | struct tblentry **new = funcblock; |
16269 | int i; | 16269 | int i; |
16270 | 16270 | ||
16271 | funcblock = (char *) funcblock + sizeof(struct tblentry *)*CMDTABLESIZE; | 16271 | funcblock = (char *) funcblock + sizeof(struct tblentry *)*CMDTABLESIZE; |
16272 | for (i = 0; i < CMDTABLESIZE; i++) { | 16272 | for (i = 0; i < CMDTABLESIZE; i++) { |
16273 | new[i] = tblentry_copy(cmdtablep[i]); | 16273 | new[i] = tblentry_copy(cmdtable[i]); |
16274 | SAVE_PTR(new[i], xasprintf("cmdtable[%d]", i), FREE); | 16274 | SAVE_PTR(new[i], xasprintf("cmdtable[%d]", i), FREE); |
16275 | } | 16275 | } |
16276 | return new; | 16276 | return new; |
@@ -16294,24 +16294,24 @@ SAVE_PTR((*vpp)->val, xasprintf("(*vpp)->val '%s'", vp->val ?: "NULL"), FREE); | |||
16294 | SLIST_COPY_END() | 16294 | SLIST_COPY_END() |
16295 | 16295 | ||
16296 | static struct datasize | 16296 | static struct datasize |
16297 | atab_size(struct datasize ds, struct alias **atabp) | 16297 | atab_size(struct datasize ds) |
16298 | { | 16298 | { |
16299 | int i; | 16299 | int i; |
16300 | ds.funcblocksize += sizeof(struct alias *)*ATABSIZE; | 16300 | ds.funcblocksize += sizeof(struct alias *)*ATABSIZE; |
16301 | for (i = 0; i < ATABSIZE; i++) | 16301 | for (i = 0; i < ATABSIZE; i++) |
16302 | ds = alias_size(ds, atabp[i]); | 16302 | ds = alias_size(ds, atab[i]); |
16303 | return ds; | 16303 | return ds; |
16304 | } | 16304 | } |
16305 | 16305 | ||
16306 | static struct alias ** | 16306 | static struct alias ** |
16307 | atab_copy(struct alias **atabp) | 16307 | atab_copy(void) |
16308 | { | 16308 | { |
16309 | struct alias **new = funcblock; | 16309 | struct alias **new = funcblock; |
16310 | int i; | 16310 | int i; |
16311 | 16311 | ||
16312 | funcblock = (char *) funcblock + sizeof(struct alias *)*ATABSIZE; | 16312 | funcblock = (char *) funcblock + sizeof(struct alias *)*ATABSIZE; |
16313 | for (i = 0; i < ATABSIZE; i++) { | 16313 | for (i = 0; i < ATABSIZE; i++) { |
16314 | new[i] = alias_copy(atabp[i]); | 16314 | new[i] = alias_copy(atab[i]); |
16315 | SAVE_PTR(new[i], xasprintf("atab[%d]", i), FREE); | 16315 | SAVE_PTR(new[i], xasprintf("atab[%d]", i), FREE); |
16316 | } | 16316 | } |
16317 | return new; | 16317 | return new; |
@@ -16361,9 +16361,10 @@ argv_copy(char **p) | |||
16361 | 16361 | ||
16362 | #if MAX_HISTORY | 16362 | #if MAX_HISTORY |
16363 | static struct datasize | 16363 | static struct datasize |
16364 | history_size(struct datasize ds, line_input_t *st) | 16364 | history_size(struct datasize ds) |
16365 | { | 16365 | { |
16366 | int i; | 16366 | int i; |
16367 | line_input_t *st = line_input_state; | ||
16367 | 16368 | ||
16368 | ds.funcblocksize += sizeof(char *) * st->cnt_history; | 16369 | ds.funcblocksize += sizeof(char *) * st->cnt_history; |
16369 | for (i = 0; i < st->cnt_history; i++) { | 16370 | for (i = 0; i < st->cnt_history; i++) { |
@@ -16373,8 +16374,9 @@ history_size(struct datasize ds, line_input_t *st) | |||
16373 | } | 16374 | } |
16374 | 16375 | ||
16375 | static char ** | 16376 | static char ** |
16376 | history_copy(line_input_t *st) | 16377 | history_copy(void) |
16377 | { | 16378 | { |
16379 | line_input_t *st = line_input_state; | ||
16378 | char **new = funcblock; | 16380 | char **new = funcblock; |
16379 | int i; | 16381 | int i; |
16380 | 16382 | ||
@@ -16421,30 +16423,31 @@ redirtab_copy(struct redirtab *rdtp) | |||
16421 | return start; | 16423 | return start; |
16422 | } | 16424 | } |
16423 | 16425 | ||
16424 | #undef funcname | ||
16425 | #undef shellparam | ||
16426 | #undef redirlist | ||
16427 | #undef vartab | ||
16428 | static struct datasize | 16426 | static struct datasize |
16429 | globals_var_size(struct datasize ds, struct globals_var *gvp) | 16427 | globals_var_size(struct datasize ds) |
16430 | { | 16428 | { |
16431 | int i; | 16429 | int i; |
16432 | 16430 | ||
16433 | ds.funcblocksize += sizeof(struct globals_var); | 16431 | ds.funcblocksize += sizeof(struct globals_var); |
16434 | ds.funcstringsize += align_len(gvp->funcname); | 16432 | ds.funcstringsize += align_len(funcname); |
16435 | ds = argv_size(ds, gvp->shellparam.p); | 16433 | ds = argv_size(ds, shellparam.p); |
16436 | ds.funcblocksize = redirtab_size(ds.funcblocksize, gvp->redirlist); | 16434 | ds.funcblocksize = redirtab_size(ds.funcblocksize, redirlist); |
16437 | for (i = 0; i < VTABSIZE; i++) | 16435 | for (i = 0; i < VTABSIZE; i++) |
16438 | ds = var_size(ds, gvp->vartab[i]); | 16436 | ds = var_size(ds, vartab[i]); |
16439 | return ds; | 16437 | return ds; |
16440 | } | 16438 | } |
16441 | 16439 | ||
16440 | #undef funcname | ||
16441 | #undef shellparam | ||
16442 | #undef redirlist | ||
16443 | #undef vartab | ||
16442 | static struct globals_var * | 16444 | static struct globals_var * |
16443 | globals_var_copy(struct globals_var *gvp) | 16445 | globals_var_copy(void) |
16444 | { | 16446 | { |
16445 | int i; | 16447 | int i; |
16446 | struct globals_var *new; | 16448 | struct globals_var *gvp, *new; |
16447 | 16449 | ||
16450 | gvp = ash_ptr_to_globals_var; | ||
16448 | new = funcblock; | 16451 | new = funcblock; |
16449 | funcblock = (char *) funcblock + sizeof(struct globals_var); | 16452 | funcblock = (char *) funcblock + sizeof(struct globals_var); |
16450 | memcpy(new, gvp, sizeof(struct globals_var)); | 16453 | memcpy(new, gvp, sizeof(struct globals_var)); |
@@ -16468,29 +16471,30 @@ globals_var_copy(struct globals_var *gvp) | |||
16468 | return new; | 16471 | return new; |
16469 | } | 16472 | } |
16470 | 16473 | ||
16471 | #undef minusc | ||
16472 | #undef curdir | ||
16473 | #undef physdir | ||
16474 | #undef arg0 | ||
16475 | #undef commandname | ||
16476 | #undef nullstr | ||
16477 | static struct datasize | 16474 | static struct datasize |
16478 | globals_misc_size(struct datasize ds, struct globals_misc *p) | 16475 | globals_misc_size(struct datasize ds) |
16479 | { | 16476 | { |
16480 | ds.funcblocksize += sizeof(struct globals_misc); | 16477 | ds.funcblocksize += sizeof(struct globals_misc); |
16481 | ds.funcstringsize += align_len(p->minusc); | 16478 | ds.funcstringsize += align_len(minusc); |
16482 | if (p->curdir != p->nullstr) | 16479 | if (curdir != nullstr) |
16483 | ds.funcstringsize += align_len(p->curdir); | 16480 | ds.funcstringsize += align_len(curdir); |
16484 | if (p->physdir != p->nullstr) | 16481 | if (physdir != nullstr) |
16485 | ds.funcstringsize += align_len(p->physdir); | 16482 | ds.funcstringsize += align_len(physdir); |
16486 | ds.funcstringsize += align_len(p->arg0); | 16483 | ds.funcstringsize += align_len(arg0); |
16487 | ds.funcstringsize += align_len(p->commandname); | 16484 | ds.funcstringsize += align_len(commandname); |
16488 | return ds; | 16485 | return ds; |
16489 | } | 16486 | } |
16490 | 16487 | ||
16488 | #undef minusc | ||
16489 | #undef curdir | ||
16490 | #undef physdir | ||
16491 | #undef arg0 | ||
16492 | #undef commandname | ||
16493 | #undef nullstr | ||
16491 | static struct globals_misc * | 16494 | static struct globals_misc * |
16492 | globals_misc_copy(struct globals_misc *p) | 16495 | globals_misc_copy(void) |
16493 | { | 16496 | { |
16497 | struct globals_misc *p = ash_ptr_to_globals_misc; | ||
16494 | struct globals_misc *new = funcblock; | 16498 | struct globals_misc *new = funcblock; |
16495 | 16499 | ||
16496 | funcblock = (char *) funcblock + sizeof(struct globals_misc); | 16500 | funcblock = (char *) funcblock + sizeof(struct globals_misc); |
@@ -16521,20 +16525,20 @@ forkshell_size(struct forkshell *fs) | |||
16521 | if (fs->fpid == FS_OPENHERE) | 16525 | if (fs->fpid == FS_OPENHERE) |
16522 | return ds; | 16526 | return ds; |
16523 | 16527 | ||
16524 | ds = globals_var_size(ds, ash_ptr_to_globals_var); | 16528 | ds = globals_var_size(ds); |
16525 | ds = globals_misc_size(ds, ash_ptr_to_globals_misc); | 16529 | ds = globals_misc_size(ds); |
16526 | ds = cmdtable_size(ds, cmdtable); | 16530 | ds = cmdtable_size(ds); |
16527 | 16531 | ||
16528 | ds.funcblocksize = calcsize(ds.funcblocksize, fs->n); | 16532 | ds.funcblocksize = calcsize(ds.funcblocksize, fs->n); |
16529 | ds = argv_size(ds, fs->argv); | 16533 | ds = argv_size(ds, fs->argv); |
16530 | 16534 | ||
16531 | if ((ENABLE_ASH_ALIAS || MAX_HISTORY) && fs->fpid != FS_SHELLEXEC) { | 16535 | if ((ENABLE_ASH_ALIAS || MAX_HISTORY) && fs->fpid != FS_SHELLEXEC) { |
16532 | #if ENABLE_ASH_ALIAS | 16536 | #if ENABLE_ASH_ALIAS |
16533 | ds = atab_size(ds, atab); | 16537 | ds = atab_size(ds); |
16534 | #endif | 16538 | #endif |
16535 | #if MAX_HISTORY | 16539 | #if MAX_HISTORY |
16536 | if (line_input_state) | 16540 | if (line_input_state) |
16537 | ds = history_size(ds, line_input_state); | 16541 | ds = history_size(ds); |
16538 | #endif | 16542 | #endif |
16539 | } | 16543 | } |
16540 | return ds; | 16544 | return ds; |
@@ -16550,9 +16554,9 @@ forkshell_copy(struct forkshell *fs, struct forkshell *new) | |||
16550 | if (fs->fpid == FS_OPENHERE) | 16554 | if (fs->fpid == FS_OPENHERE) |
16551 | return; | 16555 | return; |
16552 | 16556 | ||
16553 | new->gvp = globals_var_copy(ash_ptr_to_globals_var); | 16557 | new->gvp = globals_var_copy(); |
16554 | new->gmp = globals_misc_copy(ash_ptr_to_globals_misc); | 16558 | new->gmp = globals_misc_copy(); |
16555 | new->cmdtable = cmdtable_copy(cmdtable); | 16559 | new->cmdtable = cmdtable_copy(); |
16556 | SAVE_PTR(new->gvp, "gvp", NO_FREE); | 16560 | SAVE_PTR(new->gvp, "gvp", NO_FREE); |
16557 | SAVE_PTR(new->gmp, "gmp", NO_FREE); | 16561 | SAVE_PTR(new->gmp, "gmp", NO_FREE); |
16558 | SAVE_PTR(new->cmdtable, "cmdtable", NO_FREE); | 16562 | SAVE_PTR(new->cmdtable, "cmdtable", NO_FREE); |
@@ -16564,12 +16568,12 @@ forkshell_copy(struct forkshell *fs, struct forkshell *new) | |||
16564 | 16568 | ||
16565 | if ((ENABLE_ASH_ALIAS || MAX_HISTORY) && fs->fpid != FS_SHELLEXEC) { | 16569 | if ((ENABLE_ASH_ALIAS || MAX_HISTORY) && fs->fpid != FS_SHELLEXEC) { |
16566 | #if ENABLE_ASH_ALIAS | 16570 | #if ENABLE_ASH_ALIAS |
16567 | new->atab = atab_copy(atab); | 16571 | new->atab = atab_copy(); |
16568 | SAVE_PTR(new->atab, "atab", NO_FREE); | 16572 | SAVE_PTR(new->atab, "atab", NO_FREE); |
16569 | #endif | 16573 | #endif |
16570 | #if MAX_HISTORY | 16574 | #if MAX_HISTORY |
16571 | if (line_input_state) { | 16575 | if (line_input_state) { |
16572 | new->history = history_copy(line_input_state); | 16576 | new->history = history_copy(); |
16573 | SAVE_PTR(new->history, "history", NO_FREE); | 16577 | SAVE_PTR(new->history, "history", NO_FREE); |
16574 | new->cnt_history = line_input_state->cnt_history; | 16578 | new->cnt_history = line_input_state->cnt_history; |
16575 | } | 16579 | } |