diff --git a/sources/declare.h b/sources/declare.h index 802e171e..cf3b363b 100644 --- a/sources/declare.h +++ b/sources/declare.h @@ -69,12 +69,19 @@ /* (n) is necessary here, since the macro is sometimes passed dereferenced pointers for n */ #define NCOPY(s,t,n) { while ( (n)-- > 0 ) { *s++ = *t++; } } -/*#define NCOPY(s,t,n) { memcpy(s,t,n*sizeof(WORD)); s+=n; t+=n; n = -1; }*/ #define NCOPYI(s,t,n) { while ( (n)-- > 0 ) { *s++ = *t++; } } #define NCOPYB(s,t,n) { while ( (n)-- > 0 ) { *s++ = *t++; } } #define NCOPYI32(s,t,n) { while ( (n)-- > 0 ) { *s++ = *t++; } } #define WCOPY(s,t,n) { int nn=n; WORD *ss=(WORD *)s, *tt=(WORD *)t; while ( (nn)-- > 0 ) { *ss++ = *tt++; } } +/* Use memmove not memcpy: we can't guarantee that s, t do not overlap */ +/* Using memmove produces no measurable performance improvement or regression. */ +/*#define NCOPY(s,t,n) { memmove(s,t,(n)*sizeof(*s)); s+=n; t+=n; n=0; } +#define NCOPYI(s,t,n) { NCOPY(s,t,n); } +#define NCOPYB(s,t,n) { NCOPY(s,t,n); } +#define NCOPYI32(s,t,n) { NCOPY(s,t,n); } +#define WCOPY(s,t,n) { int nn=n; WORD *ss=(WORD *)s, *tt=(WORD *)t; NCOPY(ss,tt,nn); }*/ + #define NeedNumber(x,s,err) { int sgn = 1; \ while ( *s == ' ' || *s == '\t' || *s == '-' || *s == '+' ) { \ if ( *s == '-' ) {sgn = -sgn;} s++; } \ diff --git a/sources/proces.c b/sources/proces.c index 93ac5c80..812449b1 100644 --- a/sources/proces.c +++ b/sources/proces.c @@ -2220,11 +2220,10 @@ int InFunction(PHEAD WORD *term, WORD *termout) AR.DeferFlag = 0; v = t + *t; t += ARGHEAD; /* First term */ - w = 0; /* to appease the compilers warning devices */ - while ( from < t ) { - if ( from == u ) w = m; - *m++ = *from++; - } + LONG copy = t - from; + const LONG size = t - u; + NCOPY(m, from, copy); + w = m - size; to = m; NewSort(BHEAD0); if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) { @@ -2314,11 +2313,10 @@ int InFunction(PHEAD WORD *term, WORD *termout) && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; } AR.DeferFlag = 0; v = t + 2; - w = 0; /* to appease the compilers warning devices */ - while ( from < t ) { - if ( from == u ) w = m; - *m++ = *from++; - } + LONG copy = t - from; + const LONG size = t - u; + NCOPY(m, from, copy); + w = m - size; to = m; switch ( d->type ) { case DOLINDEX: @@ -2481,11 +2479,10 @@ int InFunction(PHEAD WORD *term, WORD *termout) u points at the start of the function t points at the start of the argument */ - w = 0; - while ( from < t ) { - if ( from == u ) w = m; - *m++ = *from++; - } + LONG copy = t - from; + const LONG size = t - u; + NCOPY(m, from, copy); + w = m - size; if ( ( numterms & MAXPOSITIVE ) == numterms ) { *m++ = -SNUMBER; *m++ = numterms & MAXPOSITIVE; w[1] += 1; @@ -2548,11 +2545,11 @@ int InFunction(PHEAD WORD *term, WORD *termout) if ( ( AN.ncmod != 0 ) && ( ( AC.modmode & ALSOFUNARGS ) == 0 ) && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; } - m = termout; w = 0; - while ( from < t ) { - if ( from == u ) w = m; - *m++ = *from++; - } + m = termout; + LONG copy = t - from; + const LONG size = t - u; + NCOPY(m, from, copy); + w = m - size; to = m; switch ( d->type ) { case DOLINDEX: diff --git a/sources/threads.c b/sources/threads.c index 9176e4c6..0a311a09 100644 --- a/sources/threads.c +++ b/sources/threads.c @@ -3543,9 +3543,9 @@ int PutToMaster(PHEAD WORD *term) fill = AT.SB.MasterFill[i]; /* Where we are filling */ top = AT.SB.MasterStop[i]; /* End of the block */ while ( j > 0 ) { - while ( j > 0 && fill < top ) { - *fill++ = *t++; j--; - } + LONG copy = MiN(top - fill, j); + j -= copy; + NCOPY(fill, t, copy); if ( j > 0 ) { /* We reached the end of the block.