aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2026-01-28 01:01:15 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2026-01-28 01:01:15 +0100
commit77d242d7ace21e4d09ec35e790f0a36a33533261 (patch)
treef88c39e9154c74f0b0c80b8eabe38ff3407ad4ea /shell
parent2051c6935856f538081b5c9e8e1a4ec06657cd1d (diff)
downloadbusybox-w32-77d242d7ace21e4d09ec35e790f0a36a33533261.tar.gz
busybox-w32-77d242d7ace21e4d09ec35e790f0a36a33533261.tar.bz2
busybox-w32-77d242d7ace21e4d09ec35e790f0a36a33533261.zip
ash: get rid of a static in cmdlookup()/delete_cmd_entry()
function old new delta cmdlookup_pp - 120 +120 find_command 953 961 +8 unsetcmd 74 76 +2 hashcmd 297 299 +2 lastcmdentry 4 - -4 delete_cmd_entry 47 43 -4 cmdlookup 132 - -132 ------------------------------------------------------------------------------ (add/remove: 1/2 grow/shrink: 3/1 up/down: 132/-140) Total: -8 bytes text data bss dec hex filename 47470 8 149 47627 ba0b shell/ash.o.orig 47466 8 145 47619 ba03 shell/ash.o Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c64
1 files changed, 38 insertions, 26 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 82cd1d574..f91ca1924 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -8539,17 +8539,12 @@ clearcmdentry(void)
8539 8539
8540/* 8540/*
8541 * Locate a command in the command hash table. If "add" is nonzero, 8541 * Locate a command in the command hash table. If "add" is nonzero,
8542 * add the command to the table if it is not already present. The 8542 * add the command to the table if it is not already present.
8543 * variable "lastcmdentry" is set to point to the address of the link
8544 * pointing to the entry, so that delete_cmd_entry can delete the
8545 * entry.
8546 * 8543 *
8547 * Interrupts must be off if called with add != 0. 8544 * Interrupts must be off if called with add != 0.
8548 */ 8545 */
8549static struct tblentry **lastcmdentry; 8546static struct tblentry **
8550 8547cmdlookup_pp(const char *name, int add)
8551static struct tblentry *
8552cmdlookup(const char *name, int add)
8553{ 8548{
8554 unsigned int hashval; 8549 unsigned int hashval;
8555 const char *p; 8550 const char *p;
@@ -8562,12 +8557,15 @@ cmdlookup(const char *name, int add)
8562 hashval += (unsigned char)*p++; 8557 hashval += (unsigned char)*p++;
8563 hashval &= 0x7FFF; 8558 hashval &= 0x7FFF;
8564 pp = &cmdtable[hashval % CMDTABLESIZE]; 8559 pp = &cmdtable[hashval % CMDTABLESIZE];
8565 for (cmdp = *pp; cmdp; cmdp = cmdp->next) { 8560 for (;;) {
8566 if (strcmp(cmdp->cmdname, name) == 0) 8561 cmdp = *pp;
8562 if (!cmdp)
8567 break; 8563 break;
8564 if (strcmp(cmdp->cmdname, name) == 0)
8565 goto ret;
8568 pp = &cmdp->next; 8566 pp = &cmdp->next;
8569 } 8567 }
8570 if (add && cmdp == NULL) { 8568 if (add) {
8571 cmdp = *pp = ckzalloc(sizeof(struct tblentry) 8569 cmdp = *pp = ckzalloc(sizeof(struct tblentry)
8572 + strlen(name) 8570 + strlen(name)
8573 /* + 1 - already done because 8571 /* + 1 - already done because
@@ -8576,21 +8574,27 @@ cmdlookup(const char *name, int add)
8576 cmdp->cmdtype = CMDUNKNOWN; 8574 cmdp->cmdtype = CMDUNKNOWN;
8577 strcpy(cmdp->cmdname, name); 8575 strcpy(cmdp->cmdname, name);
8578 } 8576 }
8579 lastcmdentry = pp; 8577 ret:
8580 return cmdp; 8578 return pp;
8579}
8580
8581static struct tblentry *
8582cmdlookup(const char *name, int add)
8583{
8584 return *cmdlookup_pp(name, add);
8581} 8585}
8582 8586
8583/* 8587/*
8584 * Delete the command entry returned on the last lookup. 8588 * Delete the command entry (should be one returned by cmdlookup_pp).
8585 */ 8589 */
8586static void 8590static void
8587delete_cmd_entry(void) 8591delete_cmd_entry(struct tblentry **pp)
8588{ 8592{
8589 struct tblentry *cmdp; 8593 struct tblentry *cmdp;
8590 8594
8591 INTOFF; 8595 INTOFF;
8592 cmdp = *lastcmdentry; 8596 cmdp = *pp;
8593 *lastcmdentry = cmdp->next; 8597 *pp = cmdp->next;
8594 if (cmdp->cmdtype == CMDFUNCTION) 8598 if (cmdp->cmdtype == CMDFUNCTION)
8595 freefunc(cmdp->param.func); 8599 freefunc(cmdp->param.func);
8596 free(cmdp); 8600 free(cmdp);
@@ -8731,6 +8735,7 @@ static void readcmdfile(char *name);
8731static void 8735static void
8732find_command(char *name, struct cmdentry *entry, int act, const char *path) 8736find_command(char *name, struct cmdentry *entry, int act, const char *path)
8733{ 8737{
8738 struct tblentry **cmdpp;
8734 struct tblentry *cmdp; 8739 struct tblentry *cmdp;
8735 int idx; 8740 int idx;
8736 int prev; 8741 int prev;
@@ -8768,7 +8773,8 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
8768 act |= DO_ALTPATH; 8773 act |= DO_ALTPATH;
8769 8774
8770 /* If name is in the table, check answer will be ok */ 8775 /* If name is in the table, check answer will be ok */
8771 cmdp = cmdlookup(name, 0); 8776 cmdpp = cmdlookup_pp(name, 0);
8777 cmdp = *cmdpp;
8772 if (cmdp != NULL) { 8778 if (cmdp != NULL) {
8773 int bit; 8779 int bit;
8774 8780
@@ -8790,13 +8796,14 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
8790 if (act & bit) { 8796 if (act & bit) {
8791 if (act & bit & DO_REGBLTIN) 8797 if (act & bit & DO_REGBLTIN)
8792 goto fail; 8798 goto fail;
8793
8794 updatetbl = 0; 8799 updatetbl = 0;
8795 cmdp = NULL; 8800 cmdp = NULL;
8796 } else if (cmdp->rehash == 0) 8801 } else if (cmdp->rehash == 0)
8797 /* if not invalidated by cd, we're done */ 8802 /* if not invalidated by cd, we're done */
8798 goto success; 8803 goto success1;
8804 /* else: cmdp->rehash is set: check/possibly delete later */
8799 } 8805 }
8806 /* either !cmdp, or cmdp->rehash is set */
8800 8807
8801 /* If %builtin not in path, check for builtin next */ 8808 /* If %builtin not in path, check for builtin next */
8802 bcmd = find_builtin(name); 8809 bcmd = find_builtin(name);
@@ -8824,7 +8831,8 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
8824#endif 8831#endif
8825 /* We have to search path. */ 8832 /* We have to search path. */
8826 prev = -1; /* where to start */ 8833 prev = -1; /* where to start */
8827 if (cmdp && cmdp->rehash) { /* doing a rehash */ 8834 if (cmdp /*TRUE: && cmdp->rehash*/) {
8835 /* doing a rehash */
8828 if (cmdp->cmdtype == CMDBUILTIN) 8836 if (cmdp->cmdtype == CMDBUILTIN)
8829 prev = builtinloc; 8837 prev = builtinloc;
8830 else 8838 else
@@ -8898,7 +8906,7 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
8898 8906
8899 /* We failed. If there was an entry for this command, delete it */ 8907 /* We failed. If there was an entry for this command, delete it */
8900 if (cmdp && updatetbl) 8908 if (cmdp && updatetbl)
8901 delete_cmd_entry(); 8909 delete_cmd_entry(cmdpp);
8902 if (act & DO_ERR) { 8910 if (act & DO_ERR) {
8903#if ENABLE_ASH_BASH_NOT_FOUND_HOOK 8911#if ENABLE_ASH_BASH_NOT_FOUND_HOOK
8904 struct tblentry *hookp = cmdlookup("command_not_found_handle", 0); 8912 struct tblentry *hookp = cmdlookup("command_not_found_handle", 0);
@@ -8931,6 +8939,7 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
8931 INTON; 8939 INTON;
8932 success: 8940 success:
8933 cmdp->rehash = 0; 8941 cmdp->rehash = 0;
8942 success1:
8934 entry->cmdtype = cmdp->cmdtype; 8943 entry->cmdtype = cmdp->cmdtype;
8935 entry->u = cmdp->param; 8944 entry->u = cmdp->param;
8936} 8945}
@@ -10635,7 +10644,8 @@ hashcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
10635 10644
10636 c = 0; 10645 c = 0;
10637 while ((name = *argptr) != NULL) { 10646 while ((name = *argptr) != NULL) {
10638 cmdp = cmdlookup(name, 0); 10647 pp = cmdlookup_pp(name, 0);
10648 cmdp = *pp;
10639 if (cmdp != NULL 10649 if (cmdp != NULL
10640 && (cmdp->cmdtype == CMDNORMAL 10650 && (cmdp->cmdtype == CMDNORMAL
10641 || (cmdp->cmdtype == CMDBUILTIN 10651 || (cmdp->cmdtype == CMDBUILTIN
@@ -10644,7 +10654,7 @@ hashcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
10644 ) 10654 )
10645 ) 10655 )
10646 ) { 10656 ) {
10647 delete_cmd_entry(); 10657 delete_cmd_entry(pp);
10648 } 10658 }
10649 find_command(name, &entry, DO_ERR, pathval()); 10659 find_command(name, &entry, DO_ERR, pathval());
10650 if (entry.cmdtype == CMDUNKNOWN) 10660 if (entry.cmdtype == CMDUNKNOWN)
@@ -14493,11 +14503,13 @@ exportcmd(int argc UNUSED_PARAM, char **argv)
14493static void 14503static void
14494unsetfunc(const char *name) 14504unsetfunc(const char *name)
14495{ 14505{
14506 struct tblentry **cmdpp;
14496 struct tblentry *cmdp; 14507 struct tblentry *cmdp;
14497 14508
14498 cmdp = cmdlookup(name, 0); 14509 cmdpp = cmdlookup_pp(name, 0);
14510 cmdp = *cmdpp;
14499 if (cmdp != NULL && cmdp->cmdtype == CMDFUNCTION) 14511 if (cmdp != NULL && cmdp->cmdtype == CMDFUNCTION)
14500 delete_cmd_entry(); 14512 delete_cmd_entry(cmdpp);
14501} 14513}
14502 14514
14503/* 14515/*