summaryrefslogtreecommitdiff
path: root/shell/ash.c
diff options
context:
space:
mode:
authorDenis Vlasenko2008-04-13 02:25:53 +0000
committerDenis Vlasenko2008-04-13 02:25:53 +0000
commit7465dbcf2a4c0a0983d40e5c0f5c057d2ed04125 (patch)
treefdbbbaab05b45dfb3f67e62e23863e4cc899584b /shell/ash.c
parentf78a656f7c287c0963d985490b3e77751b4a81bc (diff)
downloadbusybox-7465dbcf2a4c0a0983d40e5c0f5c057d2ed04125.zip
busybox-7465dbcf2a4c0a0983d40e5c0f5c057d2ed04125.tar.gz
ash: speed up NOFORK code in ash by eliminating second find_applet().
some code reduction along the way. function old new delta run_list 1971 1981 +10 run_nofork_applet_prime 181 182 +1 unsetcmd 97 96 -1 delete_cmd_entry 54 53 -1 describe_command 399 397 -2 cmdlookup 152 150 -2 evaltreenr 602 599 -3 evaltree 602 599 -3 clearcmdentry 101 98 -3 cdcmd 675 672 -3 hashcmd 305 301 -4 find_command 933 910 -23 evalcommand 1371 1229 -142 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/11 up/down: 11/-187) Total: -176 bytes
Diffstat (limited to 'shell/ash.c')
-rw-r--r--shell/ash.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/shell/ash.c b/shell/ash.c
index cc61401..409d084 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -6828,9 +6828,13 @@ struct builtincmd {
#define IS_BUILTIN_ASSIGN(b) ((b)->name[0] & 4)
struct cmdentry {
- int cmdtype;
+ smallint cmdtype; /* CMDxxx */
union param {
int index;
+ /* index >= 0 for commands without path (slashes) */
+ /* (TODO: what exactly does the value mean? PATH position?) */
+ /* index == -1 for commands with slashes */
+ /* index == (-2 - applet_no) for NOFORK applets */
const struct builtincmd *cmd;
struct funcnode *func;
} u;
@@ -6867,7 +6871,7 @@ static void find_command(char *, struct cmdentry *, int, const char *);
struct tblentry {
struct tblentry *next; /* next entry in hash chain */
union param param; /* definition of builtin function */
- short cmdtype; /* index identifying command */
+ smallint cmdtype; /* CMDxxx */
char rehash; /* if set, cd done since entry created */
char cmdname[ARB]; /* name of command */
};
@@ -7355,7 +7359,7 @@ describe_command(char *command, int describe_command_verbose)
case CMDNORMAL: {
int j = entry.u.index;
char *p;
- if (j == -1) {
+ if (j < 0) {
p = command;
} else {
do {
@@ -8747,22 +8751,17 @@ evalcommand(union node *cmd, int flags)
/* Execute the command. */
switch (cmdentry.cmdtype) {
default:
-
#if ENABLE_FEATURE_SH_NOFORK
- {
- /* TODO: don't rerun find_applet_by_name, find_command
- * already did it. Make it save applet_no somewhere */
- int applet_no = find_applet_by_name(argv[0]);
+ {
+ /* find_command() encodes applet_no as (-2 - applet_no) */
+ int applet_no = (- cmdentry.u.index - 2);
if (applet_no >= 0 && APPLET_IS_NOFORK(applet_no)) {
- struct nofork_save_area nofork_save;
-
listsetvar(varlist.list, VEXPORT|VSTACK);
- save_nofork_data(&nofork_save);
- /* run <applet>_main(), then restore nofork_save_area */
- exitstatus = run_nofork_applet_prime(&nofork_save, applet_no, argv) & 0xff;
+ /* run <applet>_main() */
+ exitstatus = run_nofork_applet(applet_no, argv);
break;
}
- }
+ }
#endif
/* Fork off a child process if necessary. */
@@ -11618,10 +11617,13 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
}
#if ENABLE_FEATURE_SH_STANDALONE
- if (find_applet_by_name(name) >= 0) {
- entry->cmdtype = CMDNORMAL;
- entry->u.index = -1;
- return;
+ {
+ int applet_no = find_applet_by_name(name);
+ if (applet_no >= 0) {
+ entry->cmdtype = CMDNORMAL;
+ entry->u.index = -2 - applet_no;
+ return;
+ }
}
#endif
@@ -12691,7 +12693,7 @@ is_right_associativity(operator prec)
|| prec == PREC(TOK_CONDITIONAL));
}
-typedef struct ARITCH_VAR_NUM {
+typedef struct {
arith_t val;
arith_t contidional_second_val;
char contidional_second_val_initialized;
@@ -12699,9 +12701,9 @@ typedef struct ARITCH_VAR_NUM {
else is variable name */
} v_n_t;
-typedef struct CHK_VAR_RECURSIVE_LOOPED {
+typedef struct chk_var_recursive_looped_t {
const char *var;
- struct CHK_VAR_RECURSIVE_LOOPED *next;
+ struct chk_var_recursive_looped_t *next;
} chk_var_recursive_looped_t;
static chk_var_recursive_looped_t *prev_chk_var_recursive;