diff options
author | Tim Janik <timj@gtk.org> | 1998-06-11 03:38:33 +0000 |
---|---|---|
committer | Tim Janik <timj@src.gnome.org> | 1998-06-11 03:38:33 +0000 |
commit | b49ead6fe5fb05ebd4e319c1a8466936a117671f (patch) | |
tree | 8a698298ed92d8168727d4851e5792855e683246 | |
parent | 580b16fb220e8ce3184e2c432776911cb3f066a5 (diff) | |
download | glib-b49ead6fe5fb05ebd4e319c1a8466936a117671f.tar.gz |
new function g_dataset_retrive_key. adjusted prealloc sizes, to take up
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.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | ChangeLog.pre-2-0 | 6 | ||||
-rw-r--r-- | ChangeLog.pre-2-10 | 6 | ||||
-rw-r--r-- | ChangeLog.pre-2-12 | 6 | ||||
-rw-r--r-- | ChangeLog.pre-2-2 | 6 | ||||
-rw-r--r-- | ChangeLog.pre-2-4 | 6 | ||||
-rw-r--r-- | ChangeLog.pre-2-6 | 6 | ||||
-rw-r--r-- | ChangeLog.pre-2-8 | 6 | ||||
-rw-r--r-- | gdataset.c | 61 | ||||
-rw-r--r-- | glib.h | 1 | ||||
-rw-r--r-- | glib/gdataset.c | 61 | ||||
-rw-r--r-- | glib/glib.h | 1 |
12 files changed, 124 insertions, 48 deletions
@@ -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, diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 020b8e3b7..98beb4634 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -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, diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 020b8e3b7..98beb4634 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -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, diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 020b8e3b7..98beb4634 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -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, diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 020b8e3b7..98beb4634 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -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, diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 020b8e3b7..98beb4634 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -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, diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 020b8e3b7..98beb4634 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -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, diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 020b8e3b7..98beb4634 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -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, diff --git a/gdataset.c b/gdataset.c index aef270cbf..86f9e9c2e 100644 --- a/gdataset.c +++ b/gdataset.c @@ -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; } @@ -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, diff --git a/glib/gdataset.c b/glib/gdataset.c index aef270cbf..86f9e9c2e 100644 --- a/glib/gdataset.c +++ b/glib/gdataset.c @@ -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/glib.h b/glib/glib.h index 021d74736..37d49e970 100644 --- a/glib/glib.h +++ b/glib/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, |