aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-08-29 20:23:20 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-08-29 20:23:20 +0200
commitb6c8434896788efa06919dc3ee73e52048805dd0 (patch)
tree2424b1d52870f7a83067f79fea5f7106bf12b6e9
parente6c483ec303adf153efa875b0b356bb47370fc56 (diff)
downloadbusybox-w32-b6c8434896788efa06919dc3ee73e52048805dd0.tar.gz
busybox-w32-b6c8434896788efa06919dc3ee73e52048805dd0.tar.bz2
busybox-w32-b6c8434896788efa06919dc3ee73e52048805dd0.zip
ash: trivial simplifications and optimizations
function old new delta rmescapes - 256 +256 memtodest 94 103 +9 evalvar 1363 1365 +2 _rmescapes 256 - -256 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 2/0 up/down: 267/-256) Total: 11 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 1ec6c96c3..f9c89f13f 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -461,15 +461,15 @@ out2str(const char *p)
461/* ============ Parser structures */ 461/* ============ Parser structures */
462 462
463/* control characters in argument strings */ 463/* control characters in argument strings */
464#define CTLESC '\201' /* escape next character */ 464#define CTLESC ((unsigned char)'\201') /* escape next character */
465#define CTLVAR '\202' /* variable defn */ 465#define CTLVAR ((unsigned char)'\202') /* variable defn */
466#define CTLENDVAR '\203' 466#define CTLENDVAR ((unsigned char)'\203')
467#define CTLBACKQ '\204' 467#define CTLBACKQ ((unsigned char)'\204')
468#define CTLQUOTE 01 /* ored with CTLBACKQ code if in quotes */ 468#define CTLQUOTE 01 /* ored with CTLBACKQ code if in quotes */
469/* CTLBACKQ | CTLQUOTE == '\205' */ 469/* CTLBACKQ | CTLQUOTE == '\205' */
470#define CTLARI '\206' /* arithmetic expression */ 470#define CTLARI ((unsigned char)'\206') /* arithmetic expression */
471#define CTLENDARI '\207' 471#define CTLENDARI ((unsigned char)'\207')
472#define CTLQUOTEMARK '\210' 472#define CTLQUOTEMARK ((unsigned char)'\210')
473 473
474/* variable substitution byte (follows CTLVAR) */ 474/* variable substitution byte (follows CTLVAR) */
475#define VSTYPE 0x0f /* type of variable substitution */ 475#define VSTYPE 0x0f /* type of variable substitution */
@@ -5379,7 +5379,7 @@ esclen(const char *start, const char *p)
5379 * Remove any CTLESC characters from a string. 5379 * Remove any CTLESC characters from a string.
5380 */ 5380 */
5381static char * 5381static char *
5382_rmescapes(char *str, int flag) 5382rmescapes(char *str, int flag)
5383{ 5383{
5384 static const char qchars[] ALIGN1 = { CTLESC, CTLQUOTEMARK, '\0' }; 5384 static const char qchars[] ALIGN1 = { CTLESC, CTLQUOTEMARK, '\0' };
5385 5385
@@ -5442,8 +5442,6 @@ _rmescapes(char *str, int flag)
5442 } 5442 }
5443 return r; 5443 return r;
5444} 5444}
5445#define rmescapes(p) _rmescapes((p), 0)
5446
5447#define pmatch(a, b) !fnmatch((a), (b), 0) 5445#define pmatch(a, b) !fnmatch((a), (b), 0)
5448 5446
5449/* 5447/*
@@ -5458,7 +5456,7 @@ preglob(const char *pattern, int quoted, int flag)
5458 if (quoted) { 5456 if (quoted) {
5459 flag |= RMESCAPE_QUOTED; 5457 flag |= RMESCAPE_QUOTED;
5460 } 5458 }
5461 return _rmescapes((char *)pattern, flag); 5459 return rmescapes((char *)pattern, flag);
5462} 5460}
5463 5461
5464/* 5462/*
@@ -5469,14 +5467,17 @@ memtodest(const char *p, size_t len, int syntax, int quotes)
5469{ 5467{
5470 char *q = expdest; 5468 char *q = expdest;
5471 5469
5472 q = makestrspace(len * 2, q); 5470 q = makestrspace(quotes ? len * 2 : len, q);
5473 5471
5474 while (len--) { 5472 while (len--) {
5475 int c = signed_char2int(*p++); 5473 int c = signed_char2int(*p++);
5476 if (!c) 5474 if (!c)
5477 continue; 5475 continue;
5478 if (quotes && (SIT(c, syntax) == CCTL || SIT(c, syntax) == CBACK)) 5476 if (quotes) {
5479 USTPUTC(CTLESC, q); 5477 int n = SIT(c, syntax);
5478 if (n == CCTL || n == CBACK)
5479 USTPUTC(CTLESC, q);
5480 }
5480 USTPUTC(c, q); 5481 USTPUTC(c, q);
5481 } 5482 }
5482 5483
@@ -5776,7 +5777,7 @@ expari(int quotes)
5776 expdest = p; 5777 expdest = p;
5777 5778
5778 if (quotes) 5779 if (quotes)
5779 rmescapes(p + 2); 5780 rmescapes(p + 2, 0);
5780 5781
5781 len = cvtnum(ash_arith(p + 2)); 5782 len = cvtnum(ash_arith(p + 2));
5782 5783
@@ -6196,7 +6197,7 @@ subevalvar(char *p, char *str, int strloc, int subtype,
6196 rmesc = startp; 6197 rmesc = startp;
6197 rmescend = (char *)stackblock() + strloc; 6198 rmescend = (char *)stackblock() + strloc;
6198 if (quotes) { 6199 if (quotes) {
6199 rmesc = _rmescapes(startp, RMESCAPE_ALLOC | RMESCAPE_GROW); 6200 rmesc = rmescapes(startp, RMESCAPE_ALLOC | RMESCAPE_GROW);
6200 if (rmesc != startp) { 6201 if (rmesc != startp) {
6201 rmescend = expdest; 6202 rmescend = expdest;
6202 startp = (char *)stackblock() + startloc; 6203 startp = (char *)stackblock() + startloc;
@@ -6939,7 +6940,7 @@ expandmeta(struct strlist *str /*, int flag*/)
6939 */ 6940 */
6940 nometa: 6941 nometa:
6941 *exparg.lastp = str; 6942 *exparg.lastp = str;
6942 rmescapes(str->text); 6943 rmescapes(str->text, 0);
6943 exparg.lastp = &str->next; 6944 exparg.lastp = &str->next;
6944 } else { 6945 } else {
6945 *exparg.lastp = NULL; 6946 *exparg.lastp = NULL;
@@ -6987,7 +6988,7 @@ expandarg(union node *arg, struct arglist *arglist, int flag)
6987 expandmeta(exparg.list /*, flag*/); 6988 expandmeta(exparg.list /*, flag*/);
6988 } else { 6989 } else {
6989 if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */ 6990 if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */
6990 rmescapes(p); 6991 rmescapes(p, 0);
6991 sp = stzalloc(sizeof(*sp)); 6992 sp = stzalloc(sizeof(*sp));
6992 sp->text = p; 6993 sp->text = p;
6993 *exparg.lastp = sp; 6994 *exparg.lastp = sp;
@@ -10412,7 +10413,7 @@ parsefname(void)
10412 TRACE(("Here document %d\n", n->type)); 10413 TRACE(("Here document %d\n", n->type));
10413 if (!noexpand(wordtext) || (i = strlen(wordtext)) == 0 || i > EOFMARKLEN) 10414 if (!noexpand(wordtext) || (i = strlen(wordtext)) == 0 || i > EOFMARKLEN)
10414 raise_error_syntax("illegal eof marker for << redirection"); 10415 raise_error_syntax("illegal eof marker for << redirection");
10415 rmescapes(wordtext); 10416 rmescapes(wordtext, 0);
10416 here->eofmark = wordtext; 10417 here->eofmark = wordtext;
10417 here->next = NULL; 10418 here->next = NULL;
10418 if (heredoclist == NULL) 10419 if (heredoclist == NULL)