new function g_dataset_retrive_key. adjusted prealloc sizes, to take up
authorTim Janik <timj@gtk.org>
Thu, 11 Jun 1998 03:38:33 +0000 (03:38 +0000)
committerTim Janik <timj@src.gnome.org>
Thu, 11 Jun 1998 03:38:33 +0000 (03:38 +0000)
Thu Jun 11 04:15:31 1998  Tim Janik  <timj@gtk.org>

        * glib.h:
        * gdataset.c: new function g_dataset_retrive_key. adjusted prealloc
        sizes, to take up less space on initial allocation.

12 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gdataset.c
glib.h
glib/gdataset.c
glib/glib.h

index 020b8e3..98beb46 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Thu Jun 11 04:15:31 1998  Tim Janik  <timj@gtk.org>
+
+        * glib.h:
+        * gdataset.c: new function g_dataset_retrive_key. adjusted prealloc
+        sizes, to take up less space on initial allocation.
+
 1998-06-10  Raja R Harinath  <harinath@cs.umn.edu>
 
        * acinclude.m4: New file.  Contains `libtool.m4' from libtool-1.2,
index 020b8e3..98beb46 100644 (file)
@@ -1,3 +1,9 @@
+Thu Jun 11 04:15:31 1998  Tim Janik  <timj@gtk.org>
+
+        * glib.h:
+        * gdataset.c: new function g_dataset_retrive_key. adjusted prealloc
+        sizes, to take up less space on initial allocation.
+
 1998-06-10  Raja R Harinath  <harinath@cs.umn.edu>
 
        * acinclude.m4: New file.  Contains `libtool.m4' from libtool-1.2,
index 020b8e3..98beb46 100644 (file)
@@ -1,3 +1,9 @@
+Thu Jun 11 04:15:31 1998  Tim Janik  <timj@gtk.org>
+
+        * glib.h:
+        * gdataset.c: new function g_dataset_retrive_key. adjusted prealloc
+        sizes, to take up less space on initial allocation.
+
 1998-06-10  Raja R Harinath  <harinath@cs.umn.edu>
 
        * acinclude.m4: New file.  Contains `libtool.m4' from libtool-1.2,
index 020b8e3..98beb46 100644 (file)
@@ -1,3 +1,9 @@
+Thu Jun 11 04:15:31 1998  Tim Janik  <timj@gtk.org>
+
+        * glib.h:
+        * gdataset.c: new function g_dataset_retrive_key. adjusted prealloc
+        sizes, to take up less space on initial allocation.
+
 1998-06-10  Raja R Harinath  <harinath@cs.umn.edu>
 
        * acinclude.m4: New file.  Contains `libtool.m4' from libtool-1.2,
index 020b8e3..98beb46 100644 (file)
@@ -1,3 +1,9 @@
+Thu Jun 11 04:15:31 1998  Tim Janik  <timj@gtk.org>
+
+        * glib.h:
+        * gdataset.c: new function g_dataset_retrive_key. adjusted prealloc
+        sizes, to take up less space on initial allocation.
+
 1998-06-10  Raja R Harinath  <harinath@cs.umn.edu>
 
        * acinclude.m4: New file.  Contains `libtool.m4' from libtool-1.2,
index 020b8e3..98beb46 100644 (file)
@@ -1,3 +1,9 @@
+Thu Jun 11 04:15:31 1998  Tim Janik  <timj@gtk.org>
+
+        * glib.h:
+        * gdataset.c: new function g_dataset_retrive_key. adjusted prealloc
+        sizes, to take up less space on initial allocation.
+
 1998-06-10  Raja R Harinath  <harinath@cs.umn.edu>
 
        * acinclude.m4: New file.  Contains `libtool.m4' from libtool-1.2,
index 020b8e3..98beb46 100644 (file)
@@ -1,3 +1,9 @@
+Thu Jun 11 04:15:31 1998  Tim Janik  <timj@gtk.org>
+
+        * glib.h:
+        * gdataset.c: new function g_dataset_retrive_key. adjusted prealloc
+        sizes, to take up less space on initial allocation.
+
 1998-06-10  Raja R Harinath  <harinath@cs.umn.edu>
 
        * acinclude.m4: New file.  Contains `libtool.m4' from libtool-1.2,
index 020b8e3..98beb46 100644 (file)
@@ -1,3 +1,9 @@
+Thu Jun 11 04:15:31 1998  Tim Janik  <timj@gtk.org>
+
+        * glib.h:
+        * gdataset.c: new function g_dataset_retrive_key. adjusted prealloc
+        sizes, to take up less space on initial allocation.
+
 1998-06-10  Raja R Harinath  <harinath@cs.umn.edu>
 
        * acinclude.m4: New file.  Contains `libtool.m4' from libtool-1.2,
index aef270c..86f9e9c 100644 (file)
@@ -23,9 +23,9 @@
 
 
 /* --- defines --- */
-#define        G_DATASET_ID_BLOCK_SIZE                 (1024)
-#define        G_DATASET_MEM_CHUNK_PREALLOC            (512)
-#define        G_DATASET_DATA_MEM_CHUNK_PREALLOC       (1024)
+#define        G_DATASET_BLOCK_SIZE                    (512)
+#define        G_DATASET_MEM_CHUNK_PREALLOC            (64)
+#define        G_DATASET_DATA_MEM_CHUNK_PREALLOC       (128)
 
 
 /* --- structures --- */
@@ -50,8 +50,10 @@ struct _GDataset
 static inline GDataset*        g_dataset_lookup        (gconstpointer dataset_location);
 static inline void     g_dataset_destroy_i     (GDataset     *dataset);
 static void            g_dataset_initialize    (void);
-static guint*          g_dataset_id_new        (void);
-
+static void            g_dataset_alloc_key     (const gchar    *string,
+                                                guint          **id,
+                                                gchar          **key);
+     
 
 /* --- variables --- */
 static GHashTable *g_dataset_location_ht = NULL;
@@ -59,8 +61,9 @@ static GHashTable *g_dataset_key_ht = NULL;
 static GDataset *g_dataset_cached = NULL;
 static GMemChunk *g_dataset_mem_chunk = NULL;
 static GMemChunk *g_dataset_data_mem_chunk = NULL;
-static guint *g_dataset_id_block = NULL;
-static guint g_dataset_id_index = G_DATASET_ID_BLOCK_SIZE + 1;
+static gchar   **g_dataset_key_array = NULL;
+static guint     g_dataset_seq_id = 0;
+
 
 
 /* --- functions --- */
@@ -285,7 +288,7 @@ g_dataset_try_key (const gchar    *key)
 guint
 g_dataset_force_id (const gchar    *key)
 {
-  register guint *id;
+  guint *id;
   
   g_return_val_if_fail (key != NULL, 0);
   
@@ -295,8 +298,10 @@ g_dataset_force_id (const gchar    *key)
   id = g_hash_table_lookup (g_dataset_key_ht, (gpointer) key);
   if (!id)
     {
-      id = g_dataset_id_new ();
-      g_hash_table_insert (g_dataset_key_ht, g_strdup (key), id);
+      gchar *new_key;
+
+      g_dataset_alloc_key (key, &id, &new_key);
+      g_hash_table_insert (g_dataset_key_ht, new_key, id);
     }
   
   return *id;
@@ -323,20 +328,28 @@ g_dataset_initialize (void)
     }
 }
 
-static guint*
-g_dataset_id_new (void)
+gchar*
+g_dataset_retrive_key (guint id)
 {
-  static guint seq_id = 1;
-  register guint *id;
-  
-  if (g_dataset_id_index >= G_DATASET_ID_BLOCK_SIZE)
-    {
-      g_dataset_id_block = g_new (guint, G_DATASET_ID_BLOCK_SIZE);
-      g_dataset_id_index = 0;
-    }
-  
-  id = &g_dataset_id_block[g_dataset_id_index++];
-  *id = seq_id++;
+  if (id > 0 && id <= g_dataset_seq_id)
+    return g_dataset_key_array[id - 1];
+  return NULL;
+}
+
+static void
+g_dataset_alloc_key (const gchar *string,
+                    guint      **id,
+                    gchar      **key)
+{
+  if (g_dataset_seq_id % G_DATASET_BLOCK_SIZE == 0)
+    g_dataset_key_array = g_realloc (g_dataset_key_array,
+                                    (g_dataset_seq_id + G_DATASET_BLOCK_SIZE) * sizeof (gchar*));
   
-  return id;
+  *key = g_new (gchar, sizeof (guint) + strlen (string) + 1);
+  *id = (guint*) *key;
+  *key += sizeof (guint);
+  strcpy (*key, string);
+  g_dataset_key_array[g_dataset_seq_id] = *key;
+  g_dataset_seq_id++;
+  **id = g_dataset_seq_id;
 }
diff --git a/glib.h b/glib.h
index 021d747..37d49e9 100644 (file)
--- a/glib.h
+++ b/glib.h
@@ -909,6 +909,7 @@ guint g_direct_hash (gconstpointer key);
 void     g_dataset_destroy             (gconstpointer   dataset_location);
 guint    g_dataset_try_key             (const gchar    *key);
 guint    g_dataset_force_id            (const gchar    *key);
+gchar*   g_dataset_retrive_key         (guint           key_id);
 gpointer  g_dataset_id_get_data                (gconstpointer   dataset_location,
                                         guint           key_id);
 void     g_dataset_id_set_data_full    (gconstpointer   dataset_location,
index aef270c..86f9e9c 100644 (file)
@@ -23,9 +23,9 @@
 
 
 /* --- defines --- */
-#define        G_DATASET_ID_BLOCK_SIZE                 (1024)
-#define        G_DATASET_MEM_CHUNK_PREALLOC            (512)
-#define        G_DATASET_DATA_MEM_CHUNK_PREALLOC       (1024)
+#define        G_DATASET_BLOCK_SIZE                    (512)
+#define        G_DATASET_MEM_CHUNK_PREALLOC            (64)
+#define        G_DATASET_DATA_MEM_CHUNK_PREALLOC       (128)
 
 
 /* --- structures --- */
@@ -50,8 +50,10 @@ struct _GDataset
 static inline GDataset*        g_dataset_lookup        (gconstpointer dataset_location);
 static inline void     g_dataset_destroy_i     (GDataset     *dataset);
 static void            g_dataset_initialize    (void);
-static guint*          g_dataset_id_new        (void);
-
+static void            g_dataset_alloc_key     (const gchar    *string,
+                                                guint          **id,
+                                                gchar          **key);
+     
 
 /* --- variables --- */
 static GHashTable *g_dataset_location_ht = NULL;
@@ -59,8 +61,9 @@ static GHashTable *g_dataset_key_ht = NULL;
 static GDataset *g_dataset_cached = NULL;
 static GMemChunk *g_dataset_mem_chunk = NULL;
 static GMemChunk *g_dataset_data_mem_chunk = NULL;
-static guint *g_dataset_id_block = NULL;
-static guint g_dataset_id_index = G_DATASET_ID_BLOCK_SIZE + 1;
+static gchar   **g_dataset_key_array = NULL;
+static guint     g_dataset_seq_id = 0;
+
 
 
 /* --- functions --- */
@@ -285,7 +288,7 @@ g_dataset_try_key (const gchar    *key)
 guint
 g_dataset_force_id (const gchar    *key)
 {
-  register guint *id;
+  guint *id;
   
   g_return_val_if_fail (key != NULL, 0);
   
@@ -295,8 +298,10 @@ g_dataset_force_id (const gchar    *key)
   id = g_hash_table_lookup (g_dataset_key_ht, (gpointer) key);
   if (!id)
     {
-      id = g_dataset_id_new ();
-      g_hash_table_insert (g_dataset_key_ht, g_strdup (key), id);
+      gchar *new_key;
+
+      g_dataset_alloc_key (key, &id, &new_key);
+      g_hash_table_insert (g_dataset_key_ht, new_key, id);
     }
   
   return *id;
@@ -323,20 +328,28 @@ g_dataset_initialize (void)
     }
 }
 
-static guint*
-g_dataset_id_new (void)
+gchar*
+g_dataset_retrive_key (guint id)
 {
-  static guint seq_id = 1;
-  register guint *id;
-  
-  if (g_dataset_id_index >= G_DATASET_ID_BLOCK_SIZE)
-    {
-      g_dataset_id_block = g_new (guint, G_DATASET_ID_BLOCK_SIZE);
-      g_dataset_id_index = 0;
-    }
-  
-  id = &g_dataset_id_block[g_dataset_id_index++];
-  *id = seq_id++;
+  if (id > 0 && id <= g_dataset_seq_id)
+    return g_dataset_key_array[id - 1];
+  return NULL;
+}
+
+static void
+g_dataset_alloc_key (const gchar *string,
+                    guint      **id,
+                    gchar      **key)
+{
+  if (g_dataset_seq_id % G_DATASET_BLOCK_SIZE == 0)
+    g_dataset_key_array = g_realloc (g_dataset_key_array,
+                                    (g_dataset_seq_id + G_DATASET_BLOCK_SIZE) * sizeof (gchar*));
   
-  return id;
+  *key = g_new (gchar, sizeof (guint) + strlen (string) + 1);
+  *id = (guint*) *key;
+  *key += sizeof (guint);
+  strcpy (*key, string);
+  g_dataset_key_array[g_dataset_seq_id] = *key;
+  g_dataset_seq_id++;
+  **id = g_dataset_seq_id;
 }
index 021d747..37d49e9 100644 (file)
@@ -909,6 +909,7 @@ guint g_direct_hash (gconstpointer key);
 void     g_dataset_destroy             (gconstpointer   dataset_location);
 guint    g_dataset_try_key             (const gchar    *key);
 guint    g_dataset_force_id            (const gchar    *key);
+gchar*   g_dataset_retrive_key         (guint           key_id);
 gpointer  g_dataset_id_get_data                (gconstpointer   dataset_location,
                                         guint           key_id);
 void     g_dataset_id_set_data_full    (gconstpointer   dataset_location,