From 364e04a0f997ed97c1035c3e5ff5ff232ab8a93c Mon Sep 17 00:00:00 2001 From: Kyryl Melekhin Date: Fri, 8 Oct 2021 18:34:18 +0000 Subject: [PATCH] use memcpy compiler assumes there might be overlap, this is incorrect. calling memcpy directly allows for better codegen --- pike.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pike.c b/pike.c index 5197008..fb49c9d 100644 --- a/pike.c +++ b/pike.c @@ -480,12 +480,12 @@ subs[i++] = nsub; \ goto next##nn; \ #define saveclist() \ -newsub(for (j = 0; j < nsubp; j++) s1->sub[j] = nsub->sub[j];, \ -for (j = 0; j < nsubp / 2 - 1; j++) s1->sub[j] = nsub->sub[j];) \ +newsub(memcpy(s1->sub, nsub->sub, osubp);, \ +memcpy(s1->sub, nsub->sub, osubp / 2);) \ #define savenlist() \ newsub(/*nop*/, /*nop*/) \ -for (j = 0; j < nsubp; j++) s1->sub[j] = nsub->sub[j]; \ +memcpy(s1->sub, nsub->sub, osubp); \ #define onnlist(nn) \ if (npc[2] == gen) \ @@ -562,7 +562,7 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp) { int rsubsize = sizeof(rsub)+(sizeof(char*)*nsubp); int i, j, c, gen, suboff = rsubsize, *npc; - int clistidx = 0, nlistidx = 0; + int clistidx = 0, nlistidx = 0, osubp = nsubp * sizeof(char*); const char *sp = s, *_sp = s; int *insts = prog->insts; int *pcs[prog->splits]; @@ -611,7 +611,7 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp) nlistidx = 0; if (!matched) { jmp_start: - newsub(for (i = 1; i < nsubp; i++) s1->sub[i] = NULL;, /*nop*/) + newsub(memset(s1->sub, 0, osubp);, /*nop*/) s1->ref = 1; s1->sub[0] = _sp; nsub = s1;