summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2016-10-12 23:25:32 +0300
committerArnold D. Robbins <arnold@skeeve.com>2016-10-12 23:25:32 +0300
commit47873e9e88e573737c96d9a0c649a05ce7d61f0d (patch)
tree442ee36df53fee4a0123671bdae4f3fd045aa506
parent1edb964dbdb07174e5822727df8ae45b32eb965f (diff)
parent43a8120a00068448c4ffa60db37bdb8e782df321 (diff)
downloadgawk-47873e9e88e573737c96d9a0c649a05ce7d61f0d.tar.gz
Merge branch 'master' into feature/typed-regex
-rw-r--r--ChangeLog8
-rw-r--r--NEWS3
-rw-r--r--awkgram.c10
-rw-r--r--awkgram.y10
4 files changed, 21 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index eed758ce..2c0090ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/NEWS b/NEWS
index feb85871..ea2bb600 100644
--- a/NEWS
+++ b/NEWS
@@ -84,6 +84,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
---------------------------
diff --git a/awkgram.c b/awkgram.c
index 0883f3fb..2d082e51 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -4622,11 +4622,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++;
}
@@ -8701,7 +8699,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;
}
diff --git a/awkgram.y b/awkgram.y
index 0ce7b833..b69aa059 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -2202,11 +2202,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++;
}
@@ -6281,7 +6279,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;
}