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.
This commit is contained in:
Tim Janik 1998-06-11 03:38:33 +00:00 committed by Tim Janik
parent 580b16fb22
commit b49ead6fe5
12 changed files with 126 additions and 50 deletions

View 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> 1998-06-10 Raja R Harinath <harinath@cs.umn.edu>
* acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2, * acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2,

View 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> 1998-06-10 Raja R Harinath <harinath@cs.umn.edu>
* acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2, * acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2,

View 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> 1998-06-10 Raja R Harinath <harinath@cs.umn.edu>
* acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2, * acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2,

View 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> 1998-06-10 Raja R Harinath <harinath@cs.umn.edu>
* acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2, * acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2,

View 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> 1998-06-10 Raja R Harinath <harinath@cs.umn.edu>
* acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2, * acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2,

View 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> 1998-06-10 Raja R Harinath <harinath@cs.umn.edu>
* acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2, * acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2,

View 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> 1998-06-10 Raja R Harinath <harinath@cs.umn.edu>
* acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2, * acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2,

View 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> 1998-06-10 Raja R Harinath <harinath@cs.umn.edu>
* acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2, * acinclude.m4: New file. Contains `libtool.m4' from libtool-1.2,

View File

@ -23,9 +23,9 @@
/* --- defines --- */ /* --- defines --- */
#define G_DATASET_ID_BLOCK_SIZE (1024) #define G_DATASET_BLOCK_SIZE (512)
#define G_DATASET_MEM_CHUNK_PREALLOC (512) #define G_DATASET_MEM_CHUNK_PREALLOC (64)
#define G_DATASET_DATA_MEM_CHUNK_PREALLOC (1024) #define G_DATASET_DATA_MEM_CHUNK_PREALLOC (128)
/* --- structures --- */ /* --- structures --- */
@ -50,8 +50,10 @@ struct _GDataset
static inline GDataset* g_dataset_lookup (gconstpointer dataset_location); static inline GDataset* g_dataset_lookup (gconstpointer dataset_location);
static inline void g_dataset_destroy_i (GDataset *dataset); static inline void g_dataset_destroy_i (GDataset *dataset);
static void g_dataset_initialize (void); 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 --- */ /* --- variables --- */
static GHashTable *g_dataset_location_ht = NULL; 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 GDataset *g_dataset_cached = NULL;
static GMemChunk *g_dataset_mem_chunk = NULL; static GMemChunk *g_dataset_mem_chunk = NULL;
static GMemChunk *g_dataset_data_mem_chunk = NULL; static GMemChunk *g_dataset_data_mem_chunk = NULL;
static guint *g_dataset_id_block = NULL; static gchar **g_dataset_key_array = NULL;
static guint g_dataset_id_index = G_DATASET_ID_BLOCK_SIZE + 1; static guint g_dataset_seq_id = 0;
/* --- functions --- */ /* --- functions --- */
@ -285,7 +288,7 @@ g_dataset_try_key (const gchar *key)
guint guint
g_dataset_force_id (const gchar *key) g_dataset_force_id (const gchar *key)
{ {
register guint *id; guint *id;
g_return_val_if_fail (key != NULL, 0); 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); id = g_hash_table_lookup (g_dataset_key_ht, (gpointer) key);
if (!id) if (!id)
{ {
id = g_dataset_id_new (); gchar *new_key;
g_hash_table_insert (g_dataset_key_ht, g_strdup (key), id);
g_dataset_alloc_key (key, &id, &new_key);
g_hash_table_insert (g_dataset_key_ht, new_key, id);
} }
return *id; return *id;
@ -323,20 +328,28 @@ g_dataset_initialize (void)
} }
} }
static guint* gchar*
g_dataset_id_new (void) g_dataset_retrive_key (guint id)
{ {
static guint seq_id = 1; if (id > 0 && id <= g_dataset_seq_id)
register guint *id; return g_dataset_key_array[id - 1];
return NULL;
if (g_dataset_id_index >= G_DATASET_ID_BLOCK_SIZE) }
{
g_dataset_id_block = g_new (guint, G_DATASET_ID_BLOCK_SIZE); static void
g_dataset_id_index = 0; g_dataset_alloc_key (const gchar *string,
} guint **id,
gchar **key)
id = &g_dataset_id_block[g_dataset_id_index++]; {
*id = seq_id++; if (g_dataset_seq_id % G_DATASET_BLOCK_SIZE == 0)
g_dataset_key_array = g_realloc (g_dataset_key_array,
return id; (g_dataset_seq_id + G_DATASET_BLOCK_SIZE) * sizeof (gchar*));
*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;
} }

1
glib.h
View File

@ -909,6 +909,7 @@ guint g_direct_hash (gconstpointer key);
void g_dataset_destroy (gconstpointer dataset_location); void g_dataset_destroy (gconstpointer dataset_location);
guint g_dataset_try_key (const gchar *key); guint g_dataset_try_key (const gchar *key);
guint g_dataset_force_id (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, gpointer g_dataset_id_get_data (gconstpointer dataset_location,
guint key_id); guint key_id);
void g_dataset_id_set_data_full (gconstpointer dataset_location, void g_dataset_id_set_data_full (gconstpointer dataset_location,

View File

@ -23,9 +23,9 @@
/* --- defines --- */ /* --- defines --- */
#define G_DATASET_ID_BLOCK_SIZE (1024) #define G_DATASET_BLOCK_SIZE (512)
#define G_DATASET_MEM_CHUNK_PREALLOC (512) #define G_DATASET_MEM_CHUNK_PREALLOC (64)
#define G_DATASET_DATA_MEM_CHUNK_PREALLOC (1024) #define G_DATASET_DATA_MEM_CHUNK_PREALLOC (128)
/* --- structures --- */ /* --- structures --- */
@ -50,8 +50,10 @@ struct _GDataset
static inline GDataset* g_dataset_lookup (gconstpointer dataset_location); static inline GDataset* g_dataset_lookup (gconstpointer dataset_location);
static inline void g_dataset_destroy_i (GDataset *dataset); static inline void g_dataset_destroy_i (GDataset *dataset);
static void g_dataset_initialize (void); 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 --- */ /* --- variables --- */
static GHashTable *g_dataset_location_ht = NULL; 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 GDataset *g_dataset_cached = NULL;
static GMemChunk *g_dataset_mem_chunk = NULL; static GMemChunk *g_dataset_mem_chunk = NULL;
static GMemChunk *g_dataset_data_mem_chunk = NULL; static GMemChunk *g_dataset_data_mem_chunk = NULL;
static guint *g_dataset_id_block = NULL; static gchar **g_dataset_key_array = NULL;
static guint g_dataset_id_index = G_DATASET_ID_BLOCK_SIZE + 1; static guint g_dataset_seq_id = 0;
/* --- functions --- */ /* --- functions --- */
@ -285,7 +288,7 @@ g_dataset_try_key (const gchar *key)
guint guint
g_dataset_force_id (const gchar *key) g_dataset_force_id (const gchar *key)
{ {
register guint *id; guint *id;
g_return_val_if_fail (key != NULL, 0); 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); id = g_hash_table_lookup (g_dataset_key_ht, (gpointer) key);
if (!id) if (!id)
{ {
id = g_dataset_id_new (); gchar *new_key;
g_hash_table_insert (g_dataset_key_ht, g_strdup (key), id);
g_dataset_alloc_key (key, &id, &new_key);
g_hash_table_insert (g_dataset_key_ht, new_key, id);
} }
return *id; return *id;
@ -323,20 +328,28 @@ g_dataset_initialize (void)
} }
} }
static guint* gchar*
g_dataset_id_new (void) g_dataset_retrive_key (guint id)
{ {
static guint seq_id = 1; if (id > 0 && id <= g_dataset_seq_id)
register guint *id; return g_dataset_key_array[id - 1];
return NULL;
if (g_dataset_id_index >= G_DATASET_ID_BLOCK_SIZE) }
{
g_dataset_id_block = g_new (guint, G_DATASET_ID_BLOCK_SIZE); static void
g_dataset_id_index = 0; g_dataset_alloc_key (const gchar *string,
} guint **id,
gchar **key)
id = &g_dataset_id_block[g_dataset_id_index++]; {
*id = seq_id++; if (g_dataset_seq_id % G_DATASET_BLOCK_SIZE == 0)
g_dataset_key_array = g_realloc (g_dataset_key_array,
return id; (g_dataset_seq_id + G_DATASET_BLOCK_SIZE) * sizeof (gchar*));
*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;
} }

View File

@ -909,6 +909,7 @@ guint g_direct_hash (gconstpointer key);
void g_dataset_destroy (gconstpointer dataset_location); void g_dataset_destroy (gconstpointer dataset_location);
guint g_dataset_try_key (const gchar *key); guint g_dataset_try_key (const gchar *key);
guint g_dataset_force_id (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, gpointer g_dataset_id_get_data (gconstpointer dataset_location,
guint key_id); guint key_id);
void g_dataset_id_set_data_full (gconstpointer dataset_location, void g_dataset_id_set_data_full (gconstpointer dataset_location,