Skip to content

Commit d93c202

Browse files
committed
perf: improve copies in InFunction
1 parent 2442e58 commit d93c202

1 file changed

Lines changed: 25 additions & 24 deletions

File tree

sources/proces.c

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,7 +2174,8 @@ int InFunction(PHEAD WORD *term, WORD *termout)
21742174
if ( AR.TePos ) {
21752175
if ( ( term + AR.TePos ) == t ) {
21762176
m = termout;
2177-
while ( from < t ) *m++ = *from++;
2177+
LONG copy = t - from;
2178+
NCOPY(m, from, copy);
21782179
*m++ = DENOMINATOR;
21792180
*m++ = t[1] + 4 + FUNHEAD + ARGHEAD;
21802181
*m++ = DIRTYFLAG;
@@ -2185,7 +2186,8 @@ int InFunction(PHEAD WORD *term, WORD *termout)
21852186
*m++ = t[1] + 4;
21862187
t[3] = -t[3];
21872188
v = t + t[1];
2188-
while ( t < v ) *m++ = *t++;
2189+
copy = v - t;
2190+
NCOPY(m, t, copy);
21892191
from[3] = -from[3];
21902192
*m++ = 1;
21912193
*m++ = 1;
@@ -2220,11 +2222,10 @@ int InFunction(PHEAD WORD *term, WORD *termout)
22202222
AR.DeferFlag = 0;
22212223
v = t + *t;
22222224
t += ARGHEAD; /* First term */
2223-
w = 0; /* to appease the compilers warning devices */
2224-
while ( from < t ) {
2225-
if ( from == u ) w = m;
2226-
*m++ = *from++;
2227-
}
2225+
LONG copy = t - from;
2226+
const LONG size = t - u;
2227+
NCOPY(m, from, copy);
2228+
w = m - size;
22282229
to = m;
22292230
NewSort(BHEAD0);
22302231
if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
@@ -2314,11 +2315,10 @@ int InFunction(PHEAD WORD *term, WORD *termout)
23142315
&& ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
23152316
AR.DeferFlag = 0;
23162317
v = t + 2;
2317-
w = 0; /* to appease the compilers warning devices */
2318-
while ( from < t ) {
2319-
if ( from == u ) w = m;
2320-
*m++ = *from++;
2321-
}
2318+
LONG copy = t - from;
2319+
const LONG size = t - u;
2320+
NCOPY(m, from, copy);
2321+
w = m - size;
23222322
to = m;
23232323
switch ( d->type ) {
23242324
case DOLINDEX:
@@ -2481,11 +2481,10 @@ int InFunction(PHEAD WORD *term, WORD *termout)
24812481
u points at the start of the function
24822482
t points at the start of the argument
24832483
*/
2484-
w = 0;
2485-
while ( from < t ) {
2486-
if ( from == u ) w = m;
2487-
*m++ = *from++;
2488-
}
2484+
LONG copy = t - from;
2485+
const LONG size = t - u;
2486+
NCOPY(m, from, copy);
2487+
w = m - size;
24892488
if ( ( numterms & MAXPOSITIVE ) == numterms ) {
24902489
*m++ = -SNUMBER; *m++ = numterms & MAXPOSITIVE;
24912490
w[1] += 1;
@@ -2505,7 +2504,8 @@ int InFunction(PHEAD WORD *term, WORD *termout)
25052504
}
25062505
from++; /* Skip our function */
25072506
r = term + *term;
2508-
while ( from < r ) *m++ = *from++;
2507+
copy = r - from;
2508+
NCOPY(m, from, copy);
25092509
if ( (m-termout) > (LONG)(AM.MaxTer/sizeof(WORD)) ) {
25102510
MLOCK(ErrorMessageLock);
25112511
MesPrint("Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/sizeof(WORD));
@@ -2548,11 +2548,11 @@ int InFunction(PHEAD WORD *term, WORD *termout)
25482548
if ( ( AN.ncmod != 0 )
25492549
&& ( ( AC.modmode & ALSOFUNARGS ) == 0 )
25502550
&& ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2551-
m = termout; w = 0;
2552-
while ( from < t ) {
2553-
if ( from == u ) w = m;
2554-
*m++ = *from++;
2555-
}
2551+
m = termout;
2552+
LONG copy = t - from;
2553+
const LONG size = t - u;
2554+
NCOPY(m, from, copy);
2555+
w = m - size;
25562556
to = m;
25572557
switch ( d->type ) {
25582558
case DOLINDEX:
@@ -2650,7 +2650,8 @@ wrongtype:;
26502650
w[1] = w[1] - 2 + (m-to);
26512651
from += 2;
26522652
term += *term;
2653-
while ( from < term ) *m++ = *from++;
2653+
copy = term - from;
2654+
NCOPY(m, from, copy);
26542655
if ( sign < 0 ) m[-1] = -m[-1];
26552656
if ( (m-termout) > (LONG)(AM.MaxTer/sizeof(WORD)) ) {
26562657
MLOCK(ErrorMessageLock);

0 commit comments

Comments
 (0)