From 43a8120a00068448c4ffa60db37bdb8e782df321 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 12 Oct 2016 23:24:19 +0300 Subject: Optimization in storing numeric string values for profiling. Update NEWS. --- awkgram.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'awkgram.c') diff --git a/awkgram.c b/awkgram.c index b7ad5779..2b88d3f6 100644 --- a/awkgram.c +++ b/awkgram.c @@ -4533,11 +4533,9 @@ negate_num(NODE *n) if ((n->flags & NUMCONSTSTR) != 0) { char *s; - emalloc(s, char *, n->stlen + 1 + 1, "negate_num"); + s = n->stptr; + memmove(& s[1], & s[0], n->stlen + 1); s[0] = '-'; - strcpy(& s[1], n->stptr); - free(n->stptr); - n->stptr = s; n->stlen++; } @@ -8598,7 +8596,9 @@ make_profile_number(double d, const char *str, size_t len) { NODE *n = make_number(d); if (do_pretty_print) { - n->stptr = estrdup(str, len); + // extra byte in case need to add minus sign in negate_num + n->stptr = estrdup(str, len + 1); + n->stptr[len] = '\0'; n->stlen = len; n->flags |= NUMCONSTSTR; } -- cgit v1.2.3