From 0f080095942b81819b521c611851ef2dbcacda99 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 17 Apr 2014 22:13:31 -0700 Subject: [PATCH 11/12] dfa: simplify dfmust initialization * src/dfa.c (dfamust): Don't initialize musts twice. Use zcalloc, not xmalloc followed by zeroing. Make result a const pointer. --- src/dfa.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/dfa.c b/src/dfa.c index fc82ad9..618a8bc 100644 --- a/src/dfa.c +++ b/src/dfa.c @@ -3928,30 +3928,20 @@ resetmust (must * mp) static void dfamust (struct dfa *d) { - must *musts; - must *mp; - char *result; + must *musts = xnmalloc (d->tindex + 1, sizeof *musts); + must *mp = musts; + char const *result = ""; size_t ri; size_t i; - bool exact; - static must must0; + bool exact = false; struct dfamust *dm; - static char empty_string[] = ""; - result = empty_string; - exact = false; - musts = xnmalloc (d->tindex + 1, sizeof *musts); - mp = musts; - for (i = 0; i <= d->tindex; ++i) - mp[i] = must0; for (i = 0; i <= d->tindex; ++i) { - mp[i].in = xmalloc (sizeof *mp[i].in); - mp[i].left = xmalloc (2); - mp[i].right = xmalloc (2); - mp[i].is = xmalloc (2); - mp[i].left[0] = mp[i].right[0] = mp[i].is[0] = '\0'; - mp[i].in[0] = NULL; + mp[i].in = xzalloc (sizeof *mp[i].in); + mp[i].left = xzalloc (2); + mp[i].right = xzalloc (2); + mp[i].is = xzalloc (2); } #ifdef DEBUG fprintf (stderr, "dfamust:\n"); -- 1.9.0