From: Tim Janik Date: Thu, 11 Jun 1998 03:38:33 +0000 (+0000) Subject: new function g_dataset_retrive_key. adjusted prealloc sizes, to take up X-Git-Tag: GLIB_1_1_0~32 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b49ead6fe5fb05ebd4e319c1a8466936a117671f;p=platform%2Fupstream%2Fglib.git new function g_dataset_retrive_key. adjusted prealloc sizes, to take up Thu Jun 11 04:15:31 1998 Tim Janik * glib.h: * gdataset.c: new function g_dataset_retrive_key. adjusted prealloc sizes, to take up less space on initial allocation. --- diff --git a/ChangeLog b/ChangeLog index 020b8e3..98beb46 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Jun 11 04:15:31 1998 Tim Janik + + * 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 * acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2, diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 020b8e3..98beb46 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,9 @@ +Thu Jun 11 04:15:31 1998 Tim Janik + + * 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 * acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2, diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 020b8e3..98beb46 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,9 @@ +Thu Jun 11 04:15:31 1998 Tim Janik + + * 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 * acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2, diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 020b8e3..98beb46 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,9 @@ +Thu Jun 11 04:15:31 1998 Tim Janik + + * 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 * acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2, diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 020b8e3..98beb46 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,9 @@ +Thu Jun 11 04:15:31 1998 Tim Janik + + * 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 * acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2, diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 020b8e3..98beb46 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,9 @@ +Thu Jun 11 04:15:31 1998 Tim Janik + + * 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 * acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2, diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 020b8e3..98beb46 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,9 @@ +Thu Jun 11 04:15:31 1998 Tim Janik + + * 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 * acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2, diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 020b8e3..98beb46 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,9 @@ +Thu Jun 11 04:15:31 1998 Tim Janik + + * 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 * acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2, diff --git a/gdataset.c b/gdataset.c index aef270c..86f9e9c 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; } diff --git a/glib.h b/glib.h index 021d747..37d49e9 100644 --- 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, diff --git a/glib/gdataset.c b/glib/gdataset.c index aef270c..86f9e9c 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 021d747..37d49e9 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,