aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormjn3 <mjn3@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-08-12 17:32:56 +0000
committermjn3 <mjn3@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-08-12 17:32:56 +0000
commit19dd6dbe00456c4ec01d0d4cbc16418256d13f47 (patch)
treec2e76689aa1f3bfc4b81c1c9802ad8ef47d4265c
parentdf353600fe296f6e694ed9edc7fd7bebf802c7f0 (diff)
downloadbusybox-w32-19dd6dbe00456c4ec01d0d4cbc16418256d13f47.tar.gz
busybox-w32-19dd6dbe00456c4ec01d0d4cbc16418256d13f47.tar.bz2
busybox-w32-19dd6dbe00456c4ec01d0d4cbc16418256d13f47.zip
I stupidly forgot one level of pointer indirection in the cmdtxt(), calcsize(),
and copynode() table implementations. Commit the fix but keep them disabled until others check them out. Uncomment "//#define CMDTXT_TABLE", "//#define CALCSIZE_TABLE", and "//#define COPYNODE_TABLE" to try them out. Saves over 600 bytes on i386. git-svn-id: svn://busybox.net/trunk/busybox@3275 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--ash.c42
-rw-r--r--shell/ash.c42
2 files changed, 46 insertions, 38 deletions
diff --git a/ash.c b/ash.c
index 417ef5d13..53fb56c2c 100644
--- a/ash.c
+++ b/ash.c
@@ -685,7 +685,7 @@ static void out2fmt (const char *, ...)
685 __attribute__((__format__(__printf__,1,2))); 685 __attribute__((__format__(__printf__,1,2)));
686static int xwrite (int, const char *, int); 686static int xwrite (int, const char *, int);
687 687
688#define outstr(p,file) fputs(p, file) 688static inline void outstr (const char *p, FILE *file) { fputs(p, file); }
689static void out1str(const char *p) { outstr(p, stdout); } 689static void out1str(const char *p) { outstr(p, stdout); }
690static void out2str(const char *p) { outstr(p, stderr); } 690static void out2str(const char *p) { outstr(p, stderr); }
691 691
@@ -7447,11 +7447,14 @@ cmdtxt(const union node *n)
7447 do { 7447 do {
7448 if (*p & CMDTXT_STRING) { /* output fixed string */ 7448 if (*p & CMDTXT_STRING) { /* output fixed string */
7449 cmdputs(cmdtxt_strings[((int)(*p & CMDTXT_OFFSETMASK) >> 1)]); 7449 cmdputs(cmdtxt_strings[((int)(*p & CMDTXT_OFFSETMASK) >> 1)]);
7450 } else if (*p & CMDTXT_CHARPTR) { /* output dynamic string */ 7450 } else {
7451 cmdputs(((const char *) n) + ((int)(*p & CMDTXT_OFFSETMASK))); 7451 const char *pf = ((const char *) n)
7452 } else { /* output field */ 7452 + ((int)(*p & CMDTXT_OFFSETMASK));
7453 cmdtxt((const union node *) 7453 if (*p & CMDTXT_CHARPTR) { /* output dynamic string */
7454 (((const char *) n) + ((int)(*p & CMDTXT_OFFSETMASK)))); 7454 cmdputs(*((const char **) pf));
7455 } else { /* output field */
7456 cmdtxt(*((const union node **) pf));
7457 }
7455 } 7458 }
7456 } while (!(*p++ & CMDTXT_NOMORE)); 7459 } while (!(*p++ & CMDTXT_NOMORE));
7457 } else if (n->type == NCMD) { 7460 } else if (n->type == NCMD) {
@@ -7630,7 +7633,7 @@ redir:
7630 break; 7633 break;
7631 } 7634 }
7632} 7635}
7633#endif 7636#endif /* CMDTXT_TABLE */
7634 7637
7635static char * 7638static char *
7636commandtext(const union node *n) 7639commandtext(const union node *n)
@@ -8832,8 +8835,9 @@ copynode(const union node *n)
8832 union node *new; 8835 union node *new;
8833 const unsigned char *p; 8836 const unsigned char *p;
8834 8837
8835 if (n == NULL) 8838 if (n == NULL) {
8836 return NULL; 8839 return NULL;
8840 }
8837 new = funcblock; 8841 new = funcblock;
8838 new->type = n->type; 8842 new->type = n->type;
8839 funcblock = (char *) funcblock + (int) nodesize[n->type]; 8843 funcblock = (char *) funcblock + (int) nodesize[n->type];
@@ -8843,12 +8847,12 @@ copynode(const union node *n)
8843 const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK)); 8847 const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
8844 8848
8845 if (!(*p & NODE_MBRMASK)) { /* standard node */ 8849 if (!(*p & NODE_MBRMASK)) { /* standard node */
8846 (union node *) nn = copynode((const union node *) no); 8850 *((union node **)nn) = copynode(*((const union node **) no));
8847 } else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */ 8851 } else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
8848 nn = nodesavestr(no); 8852 *((const char **)nn) = nodesavestr(*((const char **)no));
8849 } else if (*p & NODE_NODELIST) { /* nodelist */ 8853 } else if (*p & NODE_NODELIST) { /* nodelist */
8850 (struct nodelist *) nn 8854 *((struct nodelist **)nn)
8851 = copynodelist((const struct nodelist *) no); 8855 = copynodelist(*((const struct nodelist **) no));
8852 } else { /* integer */ 8856 } else { /* integer */
8853 *((int *) nn) = *((int *) no); 8857 *((int *) nn) = *((int *) no);
8854 } 8858 }
@@ -8862,7 +8866,7 @@ copynode(const union node *n)
8862 union node *new; 8866 union node *new;
8863 8867
8864 if (n == NULL) 8868 if (n == NULL)
8865 return NULL; 8869 return NULL;
8866 new = funcblock; 8870 new = funcblock;
8867 funcblock = (char *) funcblock + nodesize[n->type]; 8871 funcblock = (char *) funcblock + nodesize[n->type];
8868 switch (n->type) { 8872 switch (n->type) {
@@ -8961,12 +8965,12 @@ calcsize(const union node *n)
8961 const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK)); 8965 const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
8962 8966
8963 if (!(*p & NODE_MBRMASK)) { /* standard node */ 8967 if (!(*p & NODE_MBRMASK)) { /* standard node */
8964 calcsize((const union node *) no); 8968 calcsize(*((const union node **) no));
8965 } else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */ 8969 } else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
8966 funcstringsize += strlen(no) + 1; 8970 funcstringsize += strlen(*((const char **)no)) + 1;
8967 } else if (*p & NODE_NODELIST) { /* nodelist */ 8971 } else if (*p & NODE_NODELIST) { /* nodelist */
8968 sizenodelist((const struct nodelist *) no); 8972 sizenodelist(*((const struct nodelist **) no));
8969 } 8973 } /* else integer -- ignore */
8970 } while (!(*p++ & NODE_NOMORE)); 8974 } while (!(*p++ & NODE_NOMORE));
8971} 8975}
8972#else /* CALCSIZE_TABLE */ 8976#else /* CALCSIZE_TABLE */
@@ -12669,7 +12673,7 @@ findvar(struct var **vpp, const char *name)
12669/* 12673/*
12670 * Copyright (c) 1999 Herbert Xu <herbert@debian.org> 12674 * Copyright (c) 1999 Herbert Xu <herbert@debian.org>
12671 * This file contains code for the times builtin. 12675 * This file contains code for the times builtin.
12672 * $Id: ash.c,v 1.21 2001/08/10 21:11:56 andersen Exp $ 12676 * $Id: ash.c,v 1.22 2001/08/12 17:32:56 mjn3 Exp $
12673 */ 12677 */
12674static int timescmd (int argc, char **argv) 12678static int timescmd (int argc, char **argv)
12675{ 12679{
diff --git a/shell/ash.c b/shell/ash.c
index 417ef5d13..53fb56c2c 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -685,7 +685,7 @@ static void out2fmt (const char *, ...)
685 __attribute__((__format__(__printf__,1,2))); 685 __attribute__((__format__(__printf__,1,2)));
686static int xwrite (int, const char *, int); 686static int xwrite (int, const char *, int);
687 687
688#define outstr(p,file) fputs(p, file) 688static inline void outstr (const char *p, FILE *file) { fputs(p, file); }
689static void out1str(const char *p) { outstr(p, stdout); } 689static void out1str(const char *p) { outstr(p, stdout); }
690static void out2str(const char *p) { outstr(p, stderr); } 690static void out2str(const char *p) { outstr(p, stderr); }
691 691
@@ -7447,11 +7447,14 @@ cmdtxt(const union node *n)
7447 do { 7447 do {
7448 if (*p & CMDTXT_STRING) { /* output fixed string */ 7448 if (*p & CMDTXT_STRING) { /* output fixed string */
7449 cmdputs(cmdtxt_strings[((int)(*p & CMDTXT_OFFSETMASK) >> 1)]); 7449 cmdputs(cmdtxt_strings[((int)(*p & CMDTXT_OFFSETMASK) >> 1)]);
7450 } else if (*p & CMDTXT_CHARPTR) { /* output dynamic string */ 7450 } else {
7451 cmdputs(((const char *) n) + ((int)(*p & CMDTXT_OFFSETMASK))); 7451 const char *pf = ((const char *) n)
7452 } else { /* output field */ 7452 + ((int)(*p & CMDTXT_OFFSETMASK));
7453 cmdtxt((const union node *) 7453 if (*p & CMDTXT_CHARPTR) { /* output dynamic string */
7454 (((const char *) n) + ((int)(*p & CMDTXT_OFFSETMASK)))); 7454 cmdputs(*((const char **) pf));
7455 } else { /* output field */
7456 cmdtxt(*((const union node **) pf));
7457 }
7455 } 7458 }
7456 } while (!(*p++ & CMDTXT_NOMORE)); 7459 } while (!(*p++ & CMDTXT_NOMORE));
7457 } else if (n->type == NCMD) { 7460 } else if (n->type == NCMD) {
@@ -7630,7 +7633,7 @@ redir:
7630 break; 7633 break;
7631 } 7634 }
7632} 7635}
7633#endif 7636#endif /* CMDTXT_TABLE */
7634 7637
7635static char * 7638static char *
7636commandtext(const union node *n) 7639commandtext(const union node *n)
@@ -8832,8 +8835,9 @@ copynode(const union node *n)
8832 union node *new; 8835 union node *new;
8833 const unsigned char *p; 8836 const unsigned char *p;
8834 8837
8835 if (n == NULL) 8838 if (n == NULL) {
8836 return NULL; 8839 return NULL;
8840 }
8837 new = funcblock; 8841 new = funcblock;
8838 new->type = n->type; 8842 new->type = n->type;
8839 funcblock = (char *) funcblock + (int) nodesize[n->type]; 8843 funcblock = (char *) funcblock + (int) nodesize[n->type];
@@ -8843,12 +8847,12 @@ copynode(const union node *n)
8843 const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK)); 8847 const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
8844 8848
8845 if (!(*p & NODE_MBRMASK)) { /* standard node */ 8849 if (!(*p & NODE_MBRMASK)) { /* standard node */
8846 (union node *) nn = copynode((const union node *) no); 8850 *((union node **)nn) = copynode(*((const union node **) no));
8847 } else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */ 8851 } else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
8848 nn = nodesavestr(no); 8852 *((const char **)nn) = nodesavestr(*((const char **)no));
8849 } else if (*p & NODE_NODELIST) { /* nodelist */ 8853 } else if (*p & NODE_NODELIST) { /* nodelist */
8850 (struct nodelist *) nn 8854 *((struct nodelist **)nn)
8851 = copynodelist((const struct nodelist *) no); 8855 = copynodelist(*((const struct nodelist **) no));
8852 } else { /* integer */ 8856 } else { /* integer */
8853 *((int *) nn) = *((int *) no); 8857 *((int *) nn) = *((int *) no);
8854 } 8858 }
@@ -8862,7 +8866,7 @@ copynode(const union node *n)
8862 union node *new; 8866 union node *new;
8863 8867
8864 if (n == NULL) 8868 if (n == NULL)
8865 return NULL; 8869 return NULL;
8866 new = funcblock; 8870 new = funcblock;
8867 funcblock = (char *) funcblock + nodesize[n->type]; 8871 funcblock = (char *) funcblock + nodesize[n->type];
8868 switch (n->type) { 8872 switch (n->type) {
@@ -8961,12 +8965,12 @@ calcsize(const union node *n)
8961 const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK)); 8965 const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
8962 8966
8963 if (!(*p & NODE_MBRMASK)) { /* standard node */ 8967 if (!(*p & NODE_MBRMASK)) { /* standard node */
8964 calcsize((const union node *) no); 8968 calcsize(*((const union node **) no));
8965 } else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */ 8969 } else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
8966 funcstringsize += strlen(no) + 1; 8970 funcstringsize += strlen(*((const char **)no)) + 1;
8967 } else if (*p & NODE_NODELIST) { /* nodelist */ 8971 } else if (*p & NODE_NODELIST) { /* nodelist */
8968 sizenodelist((const struct nodelist *) no); 8972 sizenodelist(*((const struct nodelist **) no));
8969 } 8973 } /* else integer -- ignore */
8970 } while (!(*p++ & NODE_NOMORE)); 8974 } while (!(*p++ & NODE_NOMORE));
8971} 8975}
8972#else /* CALCSIZE_TABLE */ 8976#else /* CALCSIZE_TABLE */
@@ -12669,7 +12673,7 @@ findvar(struct var **vpp, const char *name)
12669/* 12673/*
12670 * Copyright (c) 1999 Herbert Xu <herbert@debian.org> 12674 * Copyright (c) 1999 Herbert Xu <herbert@debian.org>
12671 * This file contains code for the times builtin. 12675 * This file contains code for the times builtin.
12672 * $Id: ash.c,v 1.21 2001/08/10 21:11:56 andersen Exp $ 12676 * $Id: ash.c,v 1.22 2001/08/12 17:32:56 mjn3 Exp $
12673 */ 12677 */
12674static int timescmd (int argc, char **argv) 12678static int timescmd (int argc, char **argv)
12675{ 12679{