Browse Source

change blocksize to 8192, and make sure we set dbobs_init to 0 after obstack_free

Ben Collins 25 years ago
parent
commit
34eb6584c2
2 changed files with 24 additions and 12 deletions
  1. 6 0
      ChangeLog
  2. 18 12
      lib/nfmalloc.c

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+Mon Jan 15 00:26:45 EST 2001 Ben Collins <bcollins@debian.org>
+
+  * 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 <bcollins@debian.org>
 
   * include/dpkg-db.h: redeclare nfmalloc(), remove obstack definitions

+ 18 - 12
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;
 }