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.
This commit is contained in:
parent
dd9173c07f
commit
c639a35f50
42
ash.c
42
ash.c
@ -685,7 +685,7 @@ static void out2fmt (const char *, ...)
|
|||||||
__attribute__((__format__(__printf__,1,2)));
|
__attribute__((__format__(__printf__,1,2)));
|
||||||
static int xwrite (int, const char *, int);
|
static int xwrite (int, const char *, int);
|
||||||
|
|
||||||
#define outstr(p,file) fputs(p, file)
|
static inline void outstr (const char *p, FILE *file) { fputs(p, file); }
|
||||||
static void out1str(const char *p) { outstr(p, stdout); }
|
static void out1str(const char *p) { outstr(p, stdout); }
|
||||||
static void out2str(const char *p) { outstr(p, stderr); }
|
static void out2str(const char *p) { outstr(p, stderr); }
|
||||||
|
|
||||||
@ -7447,11 +7447,14 @@ cmdtxt(const union node *n)
|
|||||||
do {
|
do {
|
||||||
if (*p & CMDTXT_STRING) { /* output fixed string */
|
if (*p & CMDTXT_STRING) { /* output fixed string */
|
||||||
cmdputs(cmdtxt_strings[((int)(*p & CMDTXT_OFFSETMASK) >> 1)]);
|
cmdputs(cmdtxt_strings[((int)(*p & CMDTXT_OFFSETMASK) >> 1)]);
|
||||||
} else if (*p & CMDTXT_CHARPTR) { /* output dynamic string */
|
} else {
|
||||||
cmdputs(((const char *) n) + ((int)(*p & CMDTXT_OFFSETMASK)));
|
const char *pf = ((const char *) n)
|
||||||
} else { /* output field */
|
+ ((int)(*p & CMDTXT_OFFSETMASK));
|
||||||
cmdtxt((const union node *)
|
if (*p & CMDTXT_CHARPTR) { /* output dynamic string */
|
||||||
(((const char *) n) + ((int)(*p & CMDTXT_OFFSETMASK))));
|
cmdputs(*((const char **) pf));
|
||||||
|
} else { /* output field */
|
||||||
|
cmdtxt(*((const union node **) pf));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while (!(*p++ & CMDTXT_NOMORE));
|
} while (!(*p++ & CMDTXT_NOMORE));
|
||||||
} else if (n->type == NCMD) {
|
} else if (n->type == NCMD) {
|
||||||
@ -7630,7 +7633,7 @@ redir:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* CMDTXT_TABLE */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
commandtext(const union node *n)
|
commandtext(const union node *n)
|
||||||
@ -8832,8 +8835,9 @@ copynode(const union node *n)
|
|||||||
union node *new;
|
union node *new;
|
||||||
const unsigned char *p;
|
const unsigned char *p;
|
||||||
|
|
||||||
if (n == NULL)
|
if (n == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
new = funcblock;
|
new = funcblock;
|
||||||
new->type = n->type;
|
new->type = n->type;
|
||||||
funcblock = (char *) funcblock + (int) nodesize[n->type];
|
funcblock = (char *) funcblock + (int) nodesize[n->type];
|
||||||
@ -8843,12 +8847,12 @@ copynode(const union node *n)
|
|||||||
const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
|
const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
|
||||||
|
|
||||||
if (!(*p & NODE_MBRMASK)) { /* standard node */
|
if (!(*p & NODE_MBRMASK)) { /* standard node */
|
||||||
(union node *) nn = copynode((const union node *) no);
|
*((union node **)nn) = copynode(*((const union node **) no));
|
||||||
} else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
|
} else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
|
||||||
nn = nodesavestr(no);
|
*((const char **)nn) = nodesavestr(*((const char **)no));
|
||||||
} else if (*p & NODE_NODELIST) { /* nodelist */
|
} else if (*p & NODE_NODELIST) { /* nodelist */
|
||||||
(struct nodelist *) nn
|
*((struct nodelist **)nn)
|
||||||
= copynodelist((const struct nodelist *) no);
|
= copynodelist(*((const struct nodelist **) no));
|
||||||
} else { /* integer */
|
} else { /* integer */
|
||||||
*((int *) nn) = *((int *) no);
|
*((int *) nn) = *((int *) no);
|
||||||
}
|
}
|
||||||
@ -8862,7 +8866,7 @@ copynode(const union node *n)
|
|||||||
union node *new;
|
union node *new;
|
||||||
|
|
||||||
if (n == NULL)
|
if (n == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
new = funcblock;
|
new = funcblock;
|
||||||
funcblock = (char *) funcblock + nodesize[n->type];
|
funcblock = (char *) funcblock + nodesize[n->type];
|
||||||
switch (n->type) {
|
switch (n->type) {
|
||||||
@ -8961,12 +8965,12 @@ calcsize(const union node *n)
|
|||||||
const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
|
const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
|
||||||
|
|
||||||
if (!(*p & NODE_MBRMASK)) { /* standard node */
|
if (!(*p & NODE_MBRMASK)) { /* standard node */
|
||||||
calcsize((const union node *) no);
|
calcsize(*((const union node **) no));
|
||||||
} else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
|
} else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
|
||||||
funcstringsize += strlen(no) + 1;
|
funcstringsize += strlen(*((const char **)no)) + 1;
|
||||||
} else if (*p & NODE_NODELIST) { /* nodelist */
|
} else if (*p & NODE_NODELIST) { /* nodelist */
|
||||||
sizenodelist((const struct nodelist *) no);
|
sizenodelist(*((const struct nodelist **) no));
|
||||||
}
|
} /* else integer -- ignore */
|
||||||
} while (!(*p++ & NODE_NOMORE));
|
} while (!(*p++ & NODE_NOMORE));
|
||||||
}
|
}
|
||||||
#else /* CALCSIZE_TABLE */
|
#else /* CALCSIZE_TABLE */
|
||||||
@ -12669,7 +12673,7 @@ findvar(struct var **vpp, const char *name)
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1999 Herbert Xu <herbert@debian.org>
|
* Copyright (c) 1999 Herbert Xu <herbert@debian.org>
|
||||||
* This file contains code for the times builtin.
|
* This file contains code for the times builtin.
|
||||||
* $Id: ash.c,v 1.21 2001/08/10 21:11:56 andersen Exp $
|
* $Id: ash.c,v 1.22 2001/08/12 17:32:56 mjn3 Exp $
|
||||||
*/
|
*/
|
||||||
static int timescmd (int argc, char **argv)
|
static int timescmd (int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
42
shell/ash.c
42
shell/ash.c
@ -685,7 +685,7 @@ static void out2fmt (const char *, ...)
|
|||||||
__attribute__((__format__(__printf__,1,2)));
|
__attribute__((__format__(__printf__,1,2)));
|
||||||
static int xwrite (int, const char *, int);
|
static int xwrite (int, const char *, int);
|
||||||
|
|
||||||
#define outstr(p,file) fputs(p, file)
|
static inline void outstr (const char *p, FILE *file) { fputs(p, file); }
|
||||||
static void out1str(const char *p) { outstr(p, stdout); }
|
static void out1str(const char *p) { outstr(p, stdout); }
|
||||||
static void out2str(const char *p) { outstr(p, stderr); }
|
static void out2str(const char *p) { outstr(p, stderr); }
|
||||||
|
|
||||||
@ -7447,11 +7447,14 @@ cmdtxt(const union node *n)
|
|||||||
do {
|
do {
|
||||||
if (*p & CMDTXT_STRING) { /* output fixed string */
|
if (*p & CMDTXT_STRING) { /* output fixed string */
|
||||||
cmdputs(cmdtxt_strings[((int)(*p & CMDTXT_OFFSETMASK) >> 1)]);
|
cmdputs(cmdtxt_strings[((int)(*p & CMDTXT_OFFSETMASK) >> 1)]);
|
||||||
} else if (*p & CMDTXT_CHARPTR) { /* output dynamic string */
|
} else {
|
||||||
cmdputs(((const char *) n) + ((int)(*p & CMDTXT_OFFSETMASK)));
|
const char *pf = ((const char *) n)
|
||||||
} else { /* output field */
|
+ ((int)(*p & CMDTXT_OFFSETMASK));
|
||||||
cmdtxt((const union node *)
|
if (*p & CMDTXT_CHARPTR) { /* output dynamic string */
|
||||||
(((const char *) n) + ((int)(*p & CMDTXT_OFFSETMASK))));
|
cmdputs(*((const char **) pf));
|
||||||
|
} else { /* output field */
|
||||||
|
cmdtxt(*((const union node **) pf));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while (!(*p++ & CMDTXT_NOMORE));
|
} while (!(*p++ & CMDTXT_NOMORE));
|
||||||
} else if (n->type == NCMD) {
|
} else if (n->type == NCMD) {
|
||||||
@ -7630,7 +7633,7 @@ redir:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* CMDTXT_TABLE */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
commandtext(const union node *n)
|
commandtext(const union node *n)
|
||||||
@ -8832,8 +8835,9 @@ copynode(const union node *n)
|
|||||||
union node *new;
|
union node *new;
|
||||||
const unsigned char *p;
|
const unsigned char *p;
|
||||||
|
|
||||||
if (n == NULL)
|
if (n == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
new = funcblock;
|
new = funcblock;
|
||||||
new->type = n->type;
|
new->type = n->type;
|
||||||
funcblock = (char *) funcblock + (int) nodesize[n->type];
|
funcblock = (char *) funcblock + (int) nodesize[n->type];
|
||||||
@ -8843,12 +8847,12 @@ copynode(const union node *n)
|
|||||||
const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
|
const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
|
||||||
|
|
||||||
if (!(*p & NODE_MBRMASK)) { /* standard node */
|
if (!(*p & NODE_MBRMASK)) { /* standard node */
|
||||||
(union node *) nn = copynode((const union node *) no);
|
*((union node **)nn) = copynode(*((const union node **) no));
|
||||||
} else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
|
} else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
|
||||||
nn = nodesavestr(no);
|
*((const char **)nn) = nodesavestr(*((const char **)no));
|
||||||
} else if (*p & NODE_NODELIST) { /* nodelist */
|
} else if (*p & NODE_NODELIST) { /* nodelist */
|
||||||
(struct nodelist *) nn
|
*((struct nodelist **)nn)
|
||||||
= copynodelist((const struct nodelist *) no);
|
= copynodelist(*((const struct nodelist **) no));
|
||||||
} else { /* integer */
|
} else { /* integer */
|
||||||
*((int *) nn) = *((int *) no);
|
*((int *) nn) = *((int *) no);
|
||||||
}
|
}
|
||||||
@ -8862,7 +8866,7 @@ copynode(const union node *n)
|
|||||||
union node *new;
|
union node *new;
|
||||||
|
|
||||||
if (n == NULL)
|
if (n == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
new = funcblock;
|
new = funcblock;
|
||||||
funcblock = (char *) funcblock + nodesize[n->type];
|
funcblock = (char *) funcblock + nodesize[n->type];
|
||||||
switch (n->type) {
|
switch (n->type) {
|
||||||
@ -8961,12 +8965,12 @@ calcsize(const union node *n)
|
|||||||
const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
|
const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
|
||||||
|
|
||||||
if (!(*p & NODE_MBRMASK)) { /* standard node */
|
if (!(*p & NODE_MBRMASK)) { /* standard node */
|
||||||
calcsize((const union node *) no);
|
calcsize(*((const union node **) no));
|
||||||
} else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
|
} else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
|
||||||
funcstringsize += strlen(no) + 1;
|
funcstringsize += strlen(*((const char **)no)) + 1;
|
||||||
} else if (*p & NODE_NODELIST) { /* nodelist */
|
} else if (*p & NODE_NODELIST) { /* nodelist */
|
||||||
sizenodelist((const struct nodelist *) no);
|
sizenodelist(*((const struct nodelist **) no));
|
||||||
}
|
} /* else integer -- ignore */
|
||||||
} while (!(*p++ & NODE_NOMORE));
|
} while (!(*p++ & NODE_NOMORE));
|
||||||
}
|
}
|
||||||
#else /* CALCSIZE_TABLE */
|
#else /* CALCSIZE_TABLE */
|
||||||
@ -12669,7 +12673,7 @@ findvar(struct var **vpp, const char *name)
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1999 Herbert Xu <herbert@debian.org>
|
* Copyright (c) 1999 Herbert Xu <herbert@debian.org>
|
||||||
* This file contains code for the times builtin.
|
* This file contains code for the times builtin.
|
||||||
* $Id: ash.c,v 1.21 2001/08/10 21:11:56 andersen Exp $
|
* $Id: ash.c,v 1.22 2001/08/12 17:32:56 mjn3 Exp $
|
||||||
*/
|
*/
|
||||||
static int timescmd (int argc, char **argv)
|
static int timescmd (int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user