From f421a5fbef014040712a7c89e8863c7196f6ab93 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Tue, 5 Jul 2016 16:49:05 -0400 Subject: Remove FIELD flag, since it is the inverse of the MALLOC flag. --- node.c | 1 - 1 file changed, 1 deletion(-) (limited to 'node.c') diff --git a/node.c b/node.c index bb2fe437..a435e01d 100644 --- a/node.c +++ b/node.c @@ -300,7 +300,6 @@ r_dupnode(NODE *n) getnode(r); *r = *n; - r->flags &= ~FIELD; r->flags |= MALLOC; r->valref = 1; /* -- cgit v1.2.3 From ce342a04922797cb53557178c54d32c4efafda16 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Wed, 6 Jul 2016 21:31:22 -0400 Subject: Document string termination in header files and remove no-longer-needed string termination logic in various places. --- node.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'node.c') diff --git a/node.c b/node.c index a435e01d..2cd88331 100644 --- a/node.c +++ b/node.c @@ -59,7 +59,6 @@ r_force_number(NODE *n) { char *cp; char *cpend; - char save; char *ptr; extern double strtod(); @@ -133,10 +132,13 @@ r_force_number(NODE *n) /* nondec2awknum() saves and restores the byte after the string itself */ n->numbr = nondec2awknum(cp, cpend - cp, &ptr); } else { - save = *cpend; - *cpend = '\0'; + /* + * There is no need to set *cpend to '\0' because it is either + * pointing to white space or the '\0' at the end of the string. + * In either case, strtod should terminate on that character + * or earlier due to non-numeric characters. + */ n->numbr = (AWKNUM) strtod((const char *) cp, &ptr); - *cpend = save; } if (errno == 0) { @@ -941,13 +943,14 @@ get_ieee_magic_val(char *val) static bool first = true; static AWKNUM inf; static AWKNUM nan; - char save; char *ptr; - save = val[4]; - val[4] = '\0'; + /* + * There is no need to set val[4] to '\0' because it is either white + * space or the NUL character at the end of the string. Either way, + * strtod should terminate on that character. + */ AWKNUM v = strtod(val, &ptr); - val[4] = save; if (val == ptr) { /* Older strtod implementations don't support inf or nan. */ if (first) { -- cgit v1.2.3 From eb261daff5e9a96f294cd806d1fd3e68f06fdbaa Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Wed, 6 Jul 2016 22:29:58 -0400 Subject: Modify MAYBE_NUM usage and typeof function to return "strnum" only for actual numeric strings. --- node.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'node.c') diff --git a/node.c b/node.c index 2cd88331..37aa9463 100644 --- a/node.c +++ b/node.c @@ -66,9 +66,9 @@ r_force_number(NODE *n) return n; /* - * We should always set NUMCUR and clear MAYBE_NUM, and we may possibly - * change STRING to NUMBER if MAYBE_NUM was set and it's a good numeric - * string. + * We should always set NUMCUR. If MAYBE_NUM is set and it's a + * numeric string, we clear STRING and enable NUMBER, but if it's not + * numeric, we disable MAYBE_NUM. */ /* All the conditionals are an attempt to avoid the expensive strtod */ @@ -166,7 +166,8 @@ badnum: goodnum: if ((n->flags & MAYBE_NUM) != 0) { - n->flags &= ~(MAYBE_NUM|STRING); + /* leave MAYBE_NUM enabled to indicate that this is a strnum */ + n->flags &= ~STRING; n->flags |= NUMBER; } return n; -- cgit v1.2.3 From c86137f472fdf876c2c223c8d99f673f477b7554 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Fri, 8 Jul 2016 15:26:00 -0400 Subject: Optimization: support unterminated field strings inside gawk, but make terminated copies for the API. --- node.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'node.c') diff --git a/node.c b/node.c index 37aa9463..f40ccdc9 100644 --- a/node.c +++ b/node.c @@ -59,6 +59,7 @@ r_force_number(NODE *n) { char *cp; char *cpend; + char save; char *ptr; extern double strtod(); @@ -132,13 +133,10 @@ r_force_number(NODE *n) /* nondec2awknum() saves and restores the byte after the string itself */ n->numbr = nondec2awknum(cp, cpend - cp, &ptr); } else { - /* - * There is no need to set *cpend to '\0' because it is either - * pointing to white space or the '\0' at the end of the string. - * In either case, strtod should terminate on that character - * or earlier due to non-numeric characters. - */ + save = *cpend; + *cpend = '\0'; n->numbr = (AWKNUM) strtod((const char *) cp, &ptr); + *cpend = save; } if (errno == 0) { @@ -944,14 +942,13 @@ get_ieee_magic_val(char *val) static bool first = true; static AWKNUM inf; static AWKNUM nan; + char save; char *ptr; - /* - * There is no need to set val[4] to '\0' because it is either white - * space or the NUL character at the end of the string. Either way, - * strtod should terminate on that character. - */ + save = val[4]; + val[4] = '\0'; AWKNUM v = strtod(val, &ptr); + val[4] = save; if (val == ptr) { /* Older strtod implementations don't support inf or nan. */ if (first) { -- cgit v1.2.3 From cc04afb329cea035d0d9b67cd3b677e06b2f3996 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sat, 12 Nov 2016 19:12:13 +0200 Subject: Further code improvements and doc changes as diff until merge. --- node.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'node.c') diff --git a/node.c b/node.c index 491ba3bd..cef6acbe 100644 --- a/node.c +++ b/node.c @@ -67,9 +67,9 @@ r_force_number(NODE *n) return n; /* - * We should always set NUMCUR. If MAYBE_NUM is set and it's a + * We should always set NUMCUR. If USER_INPUT is set and it's a * numeric string, we clear STRING and enable NUMBER, but if it's not - * numeric, we disable MAYBE_NUM. + * numeric, we disable USER_INPUT. */ /* All the conditionals are an attempt to avoid the expensive strtod */ @@ -159,12 +159,12 @@ r_force_number(NODE *n) /* fall through to badnum */ } badnum: - n->flags &= ~MAYBE_NUM; + n->flags &= ~USER_INPUT; return n; goodnum: - if ((n->flags & MAYBE_NUM) != 0) { - /* leave MAYBE_NUM enabled to indicate that this is a strnum */ + if ((n->flags & USER_INPUT) != 0) { + /* leave USER_INPUT enabled to indicate that this is a strnum */ n->flags &= ~STRING; n->flags |= NUMBER; } -- cgit v1.2.3