aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2010-05-27 14:21:17 +0800
committermaximilian attems <max@stro.at>2011-06-03 18:44:12 +0200
commit22319814b9556654e20bf1a6af7bb435e37f3aeb (patch)
tree9d317f6d702ef987e53aacacfa3dbf1b2bb7b759
parentf18701fc6bcb64bb0067bcd9fefaa2510579b37b (diff)
downloadklibc-22319814b9556654e20bf1a6af7bb435e37f3aeb.tar.gz
[klibc] [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> Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r--usr/dash/eval.c6
-rw-r--r--usr/dash/redir.c14
2 files changed, 5 insertions, 15 deletions
diff --git a/usr/dash/eval.c b/usr/dash/eval.c
index d35fe06af9ee6..f73e6e987eedc 100644
--- a/usr/dash/eval.c
+++ b/usr/dash/eval.c
@@ -224,7 +224,8 @@ evaltree(union node *n, int flags)
evaltree(n->nredir.n, flags & EV_TESTED);
status = exitstatus;
}
- popredir(0);
+ if (n->nredir.redirect)
+ popredir(0);
goto setstatus;
case NCMD:
#ifdef notyet
@@ -879,7 +880,8 @@ raise:
}
out:
- popredir(execcmd);
+ if (cmd->ncmd.redirect)
+ popredir(execcmd);
unwindlocalvars(localvar_stop);
if (lastarg)
/* dsl: I think this is intended to be used to support
diff --git a/usr/dash/redir.c b/usr/dash/redir.c
index 54af96b05c4b1..16decfc968d36 100644
--- a/usr/dash/redir.c
+++ b/usr/dash/redir.c
@@ -72,12 +72,10 @@ MKINIT
struct redirtab {
struct redirtab *next;
int renamed[10];
- int nullredirs;
};
MKINIT struct redirtab *redirlist;
-MKINIT int nullredirs;
STATIC int openredirect(union node *);
#ifdef notyet
@@ -113,7 +111,6 @@ redirect(union node *redir, int flags)
memory[i] = 0;
memory[1] = flags & REDIR_BACKQ;
#endif
- nullredirs++;
if (!redir) {
return;
}
@@ -124,10 +121,8 @@ redirect(union node *redir, int flags)
q = ckmalloc(sizeof (struct redirtab));
q->next = redirlist;
redirlist = q;
- q->nullredirs = nullredirs - 1;
for (i = 0 ; i < 10 ; i++)
q->renamed[i] = EMPTY;
- nullredirs = 0;
sv = q;
}
n = redir;
@@ -343,8 +338,6 @@ popredir(int drop)
struct redirtab *rp;
int i;
- if (--nullredirs >= 0)
- return;
INTOFF;
rp = redirlist;
for (i = 0 ; i < 10 ; i++) {
@@ -364,7 +357,6 @@ popredir(int drop)
}
}
redirlist = rp->next;
- nullredirs = rp->nullredirs;
ckfree(rp);
INTON;
}
@@ -381,12 +373,8 @@ RESET {
/*
* Discard all saved file descriptors.
*/
- for (;;) {
- nullredirs = 0;
- if (!redirlist)
- break;
+ while (redirlist)
popredir(0);
- }
}
#endif