From 34eb6584c2f1b78b16332796420392f0475d7698 Mon Sep 17 00:00:00 2001 From: Ben Collins Date: Mon, 15 Jan 2001 05:52:20 +0000 Subject: [PATCH] change blocksize to 8192, and make sure we set dbobs_init to 0 after obstack_free --- ChangeLog | 6 ++++++ lib/nfmalloc.c | 30 ++++++++++++++++++------------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19f40957..8fe975cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Jan 15 00:26:45 EST 2001 Ben Collins + + * lib/nfmalloc.c: use obstack_copy/obstack_copy0 for nfstrsave and + nfstrnsave respectively. Also, use an 8k chunk size for now. Should reduce + some overhead, and be faster. + Sun Jan 14 23:37:30 EST 2001 Ben Collins * include/dpkg-db.h: redeclare nfmalloc(), remove obstack definitions diff --git a/lib/nfmalloc.c b/lib/nfmalloc.c index 83d59630..25760e69 100644 --- a/lib/nfmalloc.c +++ b/lib/nfmalloc.c @@ -30,9 +30,18 @@ #define obstack_chunk_alloc m_malloc #define obstack_chunk_free free -#define ALIGN_BOUNDARY 64 -#define ALIGN_MASK (ALIGN_BOUNDARY - 1) +/* We use lots of mem, so use a large chunk */ +#define CHUNK_SIZE 8192 + +#define OBSTACK_INIT if (!dbobs_init) { nfobstack_init(); } + +static void nfobstack_init(void) { + obstack_init(&db_obs); + dbobs_init = 1; + obstack_chunk_size(&db_obs) = 8192; +} + static struct obstack db_obs; static int dbobs_init = 0; @@ -42,24 +51,21 @@ inline void *nfmalloc(size_t size) void *nfmalloc(size_t size) #endif { - if (!dbobs_init) { obstack_init(&db_obs); dbobs_init = 1; } - return obstack_alloc(&db_obs, size); + OBSTACK_INIT; + return obstack_alloc(&db_obs, size); } char *nfstrsave(const char *string) { - int i = strlen(string) + 1; - char *r = nfmalloc(i); - memcpy(r, string, i); - return r; + OBSTACK_INIT; + return obstack_copy (&db_obs, string, strlen(string) + 1) } char *nfstrnsave(const char *string, int l) { - char *r = nfmalloc(l+1); - memcpy(r, string, l); - r[l] = '\0'; - return r; + OBSTACK_INIT; + return obstack_copy (&db_obs, string, l) } void nffreeall(void) { obstack_free(&db_obs, 0); + dbobs_init = 0; } -- 2.39.5