diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2007-05-12 18:14:15 +1000 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2007-05-12 18:14:15 +1000 |
commit | 245e3b5ef8341701d154df7a55dce9a290513006 (patch) | |
tree | bbe44c962e8c9ecec01cb091be7c2752aed18895 | |
parent | [REDIR] Fix redirect restore on saved file descriptors (diff) | |
download | dash-245e3b5ef8341701d154df7a55dce9a290513006.tar.gz dash-245e3b5ef8341701d154df7a55dce9a290513006.zip |
[REDIR] Size optimisations in redir.c
Add likely flag on REDIR_PUSH. Remove sv check on REDIR_SAVEFD2 (it implies REDIR_PUSH). Optimise NTOFD/NFROMFD same fd check.
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/redir.c | 23 |
2 files changed, 13 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog index bc1b94d..92fa1c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2007-05-12 Herbert Xu <herbert@gondor.apana.org.au> * Fix redirect restore on closed file descriptors. + * Size optimisations in redir.c. 2007-05-06 Herbert Xu <herbert@gondor.apana.org.au> diff --git a/src/redir.c b/src/redir.c index d4d9c39..33dbc88 100644 --- a/src/redir.c +++ b/src/redir.c @@ -119,7 +119,7 @@ redirect(union node *redir, int flags) } sv = NULL; INTOFF; - if (flags & REDIR_PUSH) { + if (likely(flags & REDIR_PUSH)) { struct redirtab *q; q = ckmalloc(sizeof (struct redirtab)); q->next = redirlist; @@ -132,12 +132,11 @@ redirect(union node *redir, int flags) } n = redir; do { - fd = n->nfile.fd; - if ((n->nfile.type == NTOFD || n->nfile.type == NFROMFD) && - n->ndup.dupfd == fd) - continue; /* redirect from/to same file descriptor */ - newfd = openredirect(n); + if (newfd < -1) + continue; + + fd = n->nfile.fd; if (sv) { p = &sv->renamed[fd]; @@ -174,7 +173,7 @@ redirect(union node *redir, int flags) if (memory[2]) out2 = &memout; #endif - if (flags & REDIR_SAVEFD2 && sv && sv->renamed[2] >= 0) + if (flags & REDIR_SAVEFD2 && sv->renamed[2] >= 0) preverrout.fd = sv->renamed[2]; } @@ -215,15 +214,17 @@ openredirect(union node *redir) if ((f = open64(fname, O_WRONLY|O_CREAT|O_APPEND, 0666)) < 0) goto ecreate; break; + case NTOFD: + case NFROMFD: + f = redir->ndup.dupfd; + if (f == redir->nfile.fd) + f = -2; + break; default: #ifdef DEBUG abort(); #endif /* Fall through to eliminate warning. */ - case NTOFD: - case NFROMFD: - f = redir->ndup.dupfd; - break; case NHERE: case NXHERE: f = openhere(redir); |