diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | awkgram.c | 10 | ||||
-rw-r--r-- | awkgram.y | 10 |
4 files changed, 21 insertions, 10 deletions
@@ -1,3 +1,11 @@ +2016-10-12 Arnold D. Robbins <arnold@skeeve.com> + + * awkgram.y (make_profile_number): Allocate an extra byte for the + string, so there's room for a minus if necessary. Store '\0' + in the right place. + (negate_num): Use memmove to shift the string up and then + insert a minus, instead of doing a fresh alloc + copy + free. + 2016-10-11 Arnold D. Robbins <arnold@skeeve.com> * awk.h (NUMCONSTSTR): New flag value. @@ -79,6 +79,9 @@ Changes from 4.1.x to 4.2.0 20. Gawk now uses fwrite_unlocked if it's available. The yields a 7% - 18% improvement in raw output speed (gawk '{ print }' on a large file). +21. Pretty printing now uses the original text of constant numeric values for + pretty printing and profiling. + Changes from 4.1.3 to 4.1.4 --------------------------- @@ -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; } @@ -2156,11 +2156,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++; } @@ -6221,7 +6219,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; } |