diff options
author | Bruno Haible <bruno@clisp.org> | 2007-02-12 02:58:17 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2007-02-12 02:58:17 +0000 |
commit | 4bc8b69ccf12c40ba0eec577b18e24bdd3cbc945 (patch) | |
tree | b81928f1bde086ce574b3df6f54fba043bb6545a /lib/mbscasestr.c | |
parent | b90fb71212755584d66a0db84bb69cf67b1052e3 (diff) | |
download | gnulib-4bc8b69ccf12c40ba0eec577b18e24bdd3cbc945.tar.gz |
Optimize memory allocation to use alloca when possible.
Diffstat (limited to 'lib/mbscasestr.c')
-rw-r--r-- | lib/mbscasestr.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/mbscasestr.c b/lib/mbscasestr.c index 838120cbad..ce28342c49 100644 --- a/lib/mbscasestr.c +++ b/lib/mbscasestr.c @@ -25,6 +25,7 @@ #include <stdbool.h> #include <stddef.h> /* for NULL, in case a nonstandard string.h lacks it */ +#include "allocsa.h" #if HAVE_MBRTOWC # include "mbuiter.h" #endif @@ -42,7 +43,7 @@ knuth_morris_pratt_unibyte (const char *haystack, const char *needle, size_t m = strlen (needle); /* Allocate the table. */ - size_t *table = (size_t *) malloc (m * sizeof (size_t)); + size_t *table = (size_t *) allocsa (m * sizeof (size_t)); if (table == NULL) return false; /* Fill the table. @@ -117,7 +118,7 @@ knuth_morris_pratt_unibyte (const char *haystack, const char *needle, } } - free (table); + freesa (table); return true; } @@ -131,7 +132,7 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle, size_t *table; /* Allocate room for needle_mbchars and the table. */ - char *memory = (char *) malloc (m * (sizeof (mbchar_t) + sizeof (size_t))); + char *memory = (char *) allocsa (m * (sizeof (mbchar_t) + sizeof (size_t))); if (memory == NULL) return false; needle_mbchars = (mbchar_t *) memory; @@ -237,7 +238,7 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle, } } - free (memory); + freesa (memory); return true; } #endif |