join: Store string length in the line struct
This gets rid of a barbarous strlen()/fwrite() construct.
--
Wolfgang Corcoran-Mathe
diff --git a/join.c b/join.c
index b2fd07e..f682023 100644
--- a/join.c
+++ b/join.c
@@ -29,6 +29,7 @@ struct field {
struct line {
char *text;
+ size_t len;
size_t nf;
size_t maxf;
struct field *fields;
@@ -152,9 +153,7 @@ prjoin(struct line *la, struct line *lb, size_t jfa, size_t
jfb)
static void
prline(struct line *lp)
{
- size_t len = strlen(lp->text);
-
- if (fwrite(lp->text, 1, len, stdout) != len)
+ if (fwrite(lp->text, 1, lp->len, stdout) != lp->len)
eprintf("fwrite:");
putchar('\n');
@@ -218,6 +217,7 @@ makeline(char *s, size_t len)
lp = ereallocarray(NULL, INIT, sizeof(struct line));
lp->text = s;
+ lp->len = len;
lp->fields = ereallocarray(NULL, INIT, sizeof(struct field));
lp->nf = 0;
lp->maxf = INIT;