Mercurial > hg > octave-nkf > gnulib-hg
changeset 8145:e8d8167b9164
Optimize memory allocation to use alloca when possible.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Mon, 12 Feb 2007 02:58:17 +0000 |
parents | cd97f59de27d |
children | b31580167c2b |
files | ChangeLog lib/c-strcasestr.c lib/c-strstr.c lib/mbscasestr.c lib/mbsstr.c lib/strcasestr.c modules/c-strcasestr modules/c-strstr modules/mbscasestr modules/mbsstr modules/strcasestr |
diffstat | 11 files changed, 46 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2007-02-11 Bruno Haible <bruno@clisp.org> + + * lib/c-strstr.c: Include allocsa.h. + (knuth_morris_pratt): Use allocsa/freesa instead of malloc/free. + * lib/c-strcasestr.c: Include allocsa.h. + (knuth_morris_pratt): Use allocsa/freesa instead of malloc/free. + * lib/strcasestr.c: Include allocsa.h. + (knuth_morris_pratt): Use allocsa/freesa instead of malloc/free. + * lib/mbsstr.c: Include allocsa.h. + (knuth_morris_pratt_unibyte, knuth_morris_pratt_multibyte): Use + allocsa/freesa instead of malloc/free. + * lib/mbscasestr.c: Include allocsa.h. + (knuth_morris_pratt_unibyte, knuth_morris_pratt_multibyte): Use + allocsa/freesa instead of malloc/free. + * modules/c-strstr (Depends-on): Add allocsa. + * modules/c-strcasestr (Depends-on): Likewise. + * modules/strcasestr (Depends-on): Likewise. + * modules/mbsstr (Depends-on): Likewise. + * modules/mbscasestr (Depends-on): Likewise. + 2007-02-11 Bruno Haible <bruno@clisp.org> * lib/mbsspn.c (mbsspn): Fix bug. Remove unnecessary strlen call.
--- a/lib/c-strcasestr.c +++ b/lib/c-strcasestr.c @@ -25,6 +25,7 @@ #include <stddef.h> #include <string.h> +#include "allocsa.h" #include "c-ctype.h" /* Knuth-Morris-Pratt algorithm. @@ -37,7 +38,7 @@ 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. @@ -112,7 +113,7 @@ } } - free (table); + freesa (table); return true; }
--- a/lib/c-strstr.c +++ b/lib/c-strstr.c @@ -25,6 +25,8 @@ #include <stdlib.h> #include <string.h> +#include "allocsa.h" + /* Knuth-Morris-Pratt algorithm. See http://en.wikipedia.org/wiki/Knuth-Morris-Pratt_algorithm Return a boolean indicating success. */ @@ -35,7 +37,7 @@ 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. @@ -109,7 +111,7 @@ } } - free (table); + freesa (table); return true; }
--- 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 @@ 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 @@ } } - free (table); + freesa (table); return true; } @@ -131,7 +132,7 @@ 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 @@ } } - free (memory); + freesa (memory); return true; } #endif
--- a/lib/mbsstr.c +++ b/lib/mbsstr.c @@ -24,6 +24,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 @@ -39,7 +40,7 @@ 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. @@ -113,7 +114,7 @@ } } - free (table); + freesa (table); return true; } @@ -127,7 +128,7 @@ 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; @@ -222,7 +223,7 @@ } } - free (memory); + freesa (memory); return true; } #endif
--- a/lib/strcasestr.c +++ b/lib/strcasestr.c @@ -25,6 +25,8 @@ #include <stdbool.h> #include <stddef.h> /* for NULL, in case a nonstandard string.h lacks it */ +#include "allocsa.h" + #define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) /* Knuth-Morris-Pratt algorithm. @@ -37,7 +39,7 @@ 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. @@ -112,7 +114,7 @@ } } - free (table); + freesa (table); return true; }
--- a/modules/c-strcasestr +++ b/modules/c-strcasestr @@ -8,6 +8,7 @@ Depends-on: c-ctype stdbool +allocsa strnlen configure.ac:
--- a/modules/c-strstr +++ b/modules/c-strstr @@ -7,6 +7,7 @@ Depends-on: stdbool +allocsa strnlen configure.ac:
--- a/modules/mbscasestr +++ b/modules/mbscasestr @@ -11,6 +11,7 @@ stdbool string mbslen +allocsa strnlen configure.ac: