Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
math code optimisation
- X-seq: zsh-workers 55
- From: P.Stephenson@xxxxxxxxxxxxx
- To: zsh-workers@xxxxxxxxxxxxxxx (Zsh hackers list)
- Subject: math code optimisation
- Date: Tue, 30 May 95 15:39:05 +0100
I just happened to look at mathevall() and noticed it was doing a lot
of unncecessary memory moving, as well as keeping some stack space
around when it wasn't using it. Actual, tidying this up seems to make
the code (OSF/1 3.0, using `size') 170 bytes larger, though there's
less in data/bss, and it looked like it made about 8k difference
(using `ps') at run time (which I don't understand since it should be
about 1.5k, even with 64-bit longs; perhaps it's getting rounded up
somewhere).
*** Src/math.c.stk Tue May 30 14:29:00 1995
--- Src/math.c Tue May 30 15:25:03 1995
***************
*** 146,152 ****
/* list of lvalues (variables) */
static int lvc;
! static char *lvals[LVCOUNT];
/**/
--- 146,152 ----
/* list of lvalues (variables) */
static int lvc;
! static char **lvals;
/**/
***************
*** 463,471 ****
struct mathvalue {
LV lval;
long val;
! }
! stack[STACKSZ];
static void push _((long val, LV lval));
--- 463,471 ----
struct mathvalue {
LV lval;
long val;
! };
! static struct mathvalue *stack;
static void push _((long val, LV lval));
***************
*** 782,790 ****
char *xptr;
long xyyval;
LV xyylval;
! char *xlvals[LVCOUNT];
int xmtok, xsp;
! struct mathvalue xstack[STACKSZ];
long ret;
xlastbase = xnoeval = xunary = xlvc = xyyval = xyylval = xsp = xmtok = 0;
--- 782,790 ----
char *xptr;
long xyyval;
LV xyylval;
! char **xlvals = 0;
int xmtok, xsp;
! struct mathvalue *xstack = 0;
long ret;
xlastbase = xnoeval = xunary = xlvc = xyyval = xyylval = xsp = xmtok = 0;
***************
*** 797,811 ****
xptr = ptr;
xyyval = yyval;
xyylval = yylval;
! memcpy(xlvals, lvals, LVCOUNT * sizeof(char *));
xmtok = mtok;
xsp = sp;
! memcpy(xstack, stack, STACKSZ * sizeof(struct mathvalue));
}
lastbase = -1;
! for (t0 = 0; t0 != LVCOUNT; t0++)
! lvals[t0] = NULL;
lvc = 0;
ptr = s;
sp = -1;
--- 797,811 ----
xptr = ptr;
xyyval = yyval;
xyylval = yylval;
! xlvals = lvals;
xmtok = mtok;
xsp = sp;
! xstack = stack;
}
+ stack = (struct mathvalue *)zalloc(STACKSZ*sizeof(struct mathvalue));
lastbase = -1;
! lvals = (char **)zcalloc(LVCOUNT*sizeof(char *));
lvc = 0;
ptr = s;
sp = -1;
***************
*** 819,824 ****
--- 819,826 ----
ret = stack[0].val;
+ zfree(lvals, LVCOUNT*sizeof(char *));
+ zfree(stack, STACKSZ*sizeof(struct mathvalue));
if (--mlevel) {
lastbase = xlastbase;
noeval = xnoeval;
***************
*** 827,837 ****
ptr = xptr;
yyval = xyyval;
yylval = xyylval;
! memcpy(lvals, xlvals, LVCOUNT * sizeof(char *));
- sp = xsp;
mtok = xmtok;
! memcpy(stack, xstack, STACKSZ * sizeof(struct mathvalue));
}
return ret;
}
--- 829,839 ----
ptr = xptr;
yyval = xyyval;
yylval = xyylval;
! lvals = xlvals;
mtok = xmtok;
! sp = xsp;
! stack = xstack;
}
return ret;
}
--
Peter Stephenson <P.Stephenson@xxxxxxxxxxxxx> Tel: +44 1792 205678 extn. 4461
WWW: http://python.swan.ac.uk/~pypeters/ Fax: +44 1792 295324
Department of Physics, University of Wales, Swansea,
Singleton Park, Swansea, SA2 8PP, U.K.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author