]> Savannah Git Hosting - gnulib.git/commitdiff
dfa: struct dfamust now uses flexible array
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 19 Dec 2019 22:35:59 +0000 (14:35 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 20 Dec 2019 03:20:53 +0000 (19:20 -0800)
* lib/dfa.c: Include flexmember.h.
(dfamust, dfamustfree): Adjust to struct dfamust change.
This saves a call to malloc+free.
* lib/dfa.h (struct dfamust): Make the final member a
flexible array member.
* modules/dfa (Depends-on): Add flexmember.

ChangeLog
lib/dfa.c
lib/dfa.h
modules/dfa

index 6d0120331c930802f4eb1ee733370381f938f619..b58c7b851fcae8757cc01c5c320bc43415d726a4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2019-12-19  Paul Eggert  <eggert@cs.ucla.edu>
 
+       dfa: struct dfamust now uses flexible array
+       * lib/dfa.c: Include flexmember.h.
+       (dfamust, dfamustfree): Adjust to struct dfamust change.
+       This saves a call to malloc+free.
+       * lib/dfa.h (struct dfamust): Make the final member a
+       flexible array member.
+       * modules/dfa (Depends-on): Add flexmember.
+
        dfa: fast->small for array elements
        * lib/dfa.c (charclass_word): Use uint_least64_t not uint_fast64_t,
        since this type is used in arrays.  This change is more for
index a7cd3e84fbd8fe9cee11fe8f2f326978836ec0a2..734e74e29f019f70cf26cce2783c6b541770eac1 100644 (file)
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -24,6 +24,8 @@
 
 #include "dfa.h"
 
+#include "flexmember.h"
+
 #include <assert.h>
 #include <ctype.h>
 #include <stdint.h>
@@ -4272,11 +4274,11 @@ dfamust (struct dfa const *d)
   struct dfamust *dm = NULL;
   if (*result)
     {
-      dm = xmalloc (sizeof *dm);
+      dm = xmalloc (FLEXSIZEOF (struct dfamust, must, strlen (result) + 1));
       dm->exact = exact;
       dm->begline = begline;
       dm->endline = endline;
-      dm->must = xstrdup (result);
+      strcpy (dm->must, result);
     }
 
   while (mp)
@@ -4292,7 +4294,6 @@ dfamust (struct dfa const *d)
 void
 dfamustfree (struct dfamust *dm)
 {
-  free (dm->must);
   free (dm);
 }
 
index 0da597fc9f462254d9872ec08a03bb2a6fdccd72..56e2ee000f16c865046ed340dfe40bd1e7173ac4 100644 (file)
--- a/lib/dfa.h
+++ b/lib/dfa.h
@@ -31,7 +31,7 @@ struct dfamust
   bool exact;
   bool begline;
   bool endline;
-  char *must;
+  char must[FLEXIBLE_ARRAY_MEMBER];
 };
 
 /* The dfa structure. It is completely opaque. */
index ee5bec85d8851cd713780e6f35ce8ce4fb193758..f1b00fe1edaa7885155e6dccfa6f0c8c0d8271f1 100644 (file)
@@ -11,6 +11,7 @@ Depends-on:
 assert
 c99
 ctype
+flexmember
 intprops
 isblank
 locale