aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-10-25 21:46:03 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-10-25 21:46:03 +0200
commiteaf9436b08f68be8b96730307fe1da1faf374ee0 (patch)
tree88f6a907a913ef8a72a47c0b1ea0725fa8c3ea93 /shell
parent2a6d29ad5ce652c03ed8324a0d14f62594f2dd84 (diff)
downloadbusybox-w32-eaf9436b08f68be8b96730307fe1da1faf374ee0.tar.gz
busybox-w32-eaf9436b08f68be8b96730307fe1da1faf374ee0.tar.bz2
busybox-w32-eaf9436b08f68be8b96730307fe1da1faf374ee0.zip
ash: [REDIR] Move null redirect checks into caller
Upstream commit: Date: Thu, 27 May 2010 14:21:17 +0800 [REDIR] Move null redirect checks into caller The null redirect checks were added as an optimisation to avoid unnecessary memory allocations. However, we could avoid this completely by simply making the caller avoid making a redirection unless it is not null. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta evaltree 784 809 +25 evalcommand 1251 1261 +10 hashvar 59 62 +3 dotcmd 321 319 -2 clearredir 37 30 -7 popredir 183 162 -21 redirect 1264 1233 -31 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/4 up/down: 63/-61) Total: -23 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/shell/ash.c b/shell/ash.c
index dc0f60747..dc26bc142 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -1951,7 +1951,6 @@ struct redirtab;
1951struct globals_var { 1951struct globals_var {
1952 struct shparam shellparam; /* $@ current positional parameters */ 1952 struct shparam shellparam; /* $@ current positional parameters */
1953 struct redirtab *redirlist; 1953 struct redirtab *redirlist;
1954 int g_nullredirs;
1955 int preverrout_fd; /* save fd2 before print debug if xflag is set. */ 1954 int preverrout_fd; /* save fd2 before print debug if xflag is set. */
1956 struct var *vartab[VTABSIZE]; 1955 struct var *vartab[VTABSIZE];
1957 struct var varinit[ARRAY_SIZE(varinit_data)]; 1956 struct var varinit[ARRAY_SIZE(varinit_data)];
@@ -1960,7 +1959,6 @@ extern struct globals_var *const ash_ptr_to_globals_var;
1960#define G_var (*ash_ptr_to_globals_var) 1959#define G_var (*ash_ptr_to_globals_var)
1961#define shellparam (G_var.shellparam ) 1960#define shellparam (G_var.shellparam )
1962//#define redirlist (G_var.redirlist ) 1961//#define redirlist (G_var.redirlist )
1963#define g_nullredirs (G_var.g_nullredirs )
1964#define preverrout_fd (G_var.preverrout_fd) 1962#define preverrout_fd (G_var.preverrout_fd)
1965#define vartab (G_var.vartab ) 1963#define vartab (G_var.vartab )
1966#define varinit (G_var.varinit ) 1964#define varinit (G_var.varinit )
@@ -5216,7 +5214,6 @@ struct two_fd_t {
5216}; 5214};
5217struct redirtab { 5215struct redirtab {
5218 struct redirtab *next; 5216 struct redirtab *next;
5219 int nullredirs;
5220 int pair_count; 5217 int pair_count;
5221 struct two_fd_t two_fd[]; 5218 struct two_fd_t two_fd[];
5222}; 5219};
@@ -5295,7 +5292,6 @@ redirect(union node *redir, int flags)
5295 int newfd; 5292 int newfd;
5296 int copied_fd2 = -1; 5293 int copied_fd2 = -1;
5297 5294
5298 g_nullredirs++;
5299 if (!redir) { 5295 if (!redir) {
5300 return; 5296 return;
5301 } 5297 }
@@ -5317,8 +5313,6 @@ redirect(union node *redir, int flags)
5317 sv->next = redirlist; 5313 sv->next = redirlist;
5318 sv->pair_count = sv_pos; 5314 sv->pair_count = sv_pos;
5319 redirlist = sv; 5315 redirlist = sv;
5320 sv->nullredirs = g_nullredirs - 1;
5321 g_nullredirs = 0;
5322 while (sv_pos > 0) { 5316 while (sv_pos > 0) {
5323 sv_pos--; 5317 sv_pos--;
5324 sv->two_fd[sv_pos].orig = sv->two_fd[sv_pos].copy = EMPTY; 5318 sv->two_fd[sv_pos].orig = sv->two_fd[sv_pos].copy = EMPTY;
@@ -5430,7 +5424,7 @@ popredir(int drop, int restore)
5430 struct redirtab *rp; 5424 struct redirtab *rp;
5431 int i; 5425 int i;
5432 5426
5433 if (--g_nullredirs >= 0 || redirlist == NULL) 5427 if (redirlist == NULL)
5434 return; 5428 return;
5435 INT_OFF; 5429 INT_OFF;
5436 rp = redirlist; 5430 rp = redirlist;
@@ -5452,7 +5446,6 @@ popredir(int drop, int restore)
5452 } 5446 }
5453 } 5447 }
5454 redirlist = rp->next; 5448 redirlist = rp->next;
5455 g_nullredirs = rp->nullredirs;
5456 free(rp); 5449 free(rp);
5457 INT_ON; 5450 INT_ON;
5458} 5451}
@@ -5467,12 +5460,8 @@ popredir(int drop, int restore)
5467static void 5460static void
5468clearredir(int drop) 5461clearredir(int drop)
5469{ 5462{
5470 for (;;) { 5463 while (redirlist)
5471 g_nullredirs = 0;
5472 if (!redirlist)
5473 break;
5474 popredir(drop, /*restore:*/ 0); 5464 popredir(drop, /*restore:*/ 0);
5475 }
5476} 5465}
5477 5466
5478static int 5467static int
@@ -8573,7 +8562,8 @@ evaltree(union node *n, int flags)
8573 if (!status) { 8562 if (!status) {
8574 status = evaltree(n->nredir.n, flags & EV_TESTED); 8563 status = evaltree(n->nredir.n, flags & EV_TESTED);
8575 } 8564 }
8576 popredir(/*drop:*/ 0, /*restore:*/ 0 /* not sure */); 8565 if (n->nredir.redirect)
8566 popredir(/*drop:*/ 0, /*restore:*/ 0 /* not sure */);
8577 goto setstatus; 8567 goto setstatus;
8578 case NCMD: 8568 case NCMD:
8579 evalfn = evalcommand; 8569 evalfn = evalcommand;
@@ -9645,7 +9635,8 @@ evalcommand(union node *cmd, int flags)
9645 } /* switch */ 9635 } /* switch */
9646 9636
9647 out: 9637 out:
9648 popredir(/*drop:*/ cmd_is_exec, /*restore:*/ cmd_is_exec); 9638 if (cmd->ncmd.redirect)
9639 popredir(/*drop:*/ cmd_is_exec, /*restore:*/ cmd_is_exec);
9649 if (lastarg) { 9640 if (lastarg) {
9650 /* dsl: I think this is intended to be used to support 9641 /* dsl: I think this is intended to be used to support
9651 * '_' in 'vi' command mode during line editing... 9642 * '_' in 'vi' command mode during line editing...