mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-29 10:36:52 +02:00
removed g_dataset_try_key, g_dataset_force_id and g_dataset_retrive_key in
Fri Jun 19 03:11:02 1998 Tim Janik <timj@gtk.org> * gdataset.c: removed g_dataset_try_key, g_dataset_force_id and g_dataset_retrive_key in favour of GQuarks. a GQuark is an numeric id wich is associated with a certain string. (g_quark_try_string): try to get the quark associated with this string, if the lookup failed return 0. (g_quark_from_string): get the associated quark for a string, if there isn't currently a GQuark associated with this string, then allocate a new quark and return that. (g_quark_from_static_string): like the above function, but the string isn't strdup()ed to save memory. (g_quark_to_string): get the string that is associated with a certain GQuark. * gdataset.c (g_dataset_id_set_data_full): invoke the destroy function _after_ the new data has been setup.
This commit is contained in:
parent
12edfe9084
commit
afdf8b93a3
18
ChangeLog
18
ChangeLog
@ -1,3 +1,21 @@
|
|||||||
|
Fri Jun 19 03:11:02 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* gdataset.c: removed g_dataset_try_key, g_dataset_force_id and
|
||||||
|
g_dataset_retrive_key in favour of GQuarks.
|
||||||
|
a GQuark is an numeric id wich is associated with a certain string.
|
||||||
|
(g_quark_try_string): try to get the quark associated with this string,
|
||||||
|
if the lookup failed return 0.
|
||||||
|
(g_quark_from_string): get the associated quark for a string, if there
|
||||||
|
isn't currently a GQuark associated with this string, then allocate a
|
||||||
|
new quark and return that.
|
||||||
|
(g_quark_from_static_string): like the above function, but the string
|
||||||
|
isn't strdup()ed to save memory.
|
||||||
|
(g_quark_to_string): get the string that is associated with a certain
|
||||||
|
GQuark.
|
||||||
|
|
||||||
|
* gdataset.c (g_dataset_id_set_data_full): invoke the destroy function
|
||||||
|
_after_ the new data has been setup.
|
||||||
|
|
||||||
Thu Jun 18 02:35:21 1998 Owen Taylor <otaylor@gtk.org>
|
Thu Jun 18 02:35:21 1998 Owen Taylor <otaylor@gtk.org>
|
||||||
|
|
||||||
* glib.h: Changed messages for g_return_[val]_if_fail to
|
* glib.h: Changed messages for g_return_[val]_if_fail to
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
Fri Jun 19 03:11:02 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* gdataset.c: removed g_dataset_try_key, g_dataset_force_id and
|
||||||
|
g_dataset_retrive_key in favour of GQuarks.
|
||||||
|
a GQuark is an numeric id wich is associated with a certain string.
|
||||||
|
(g_quark_try_string): try to get the quark associated with this string,
|
||||||
|
if the lookup failed return 0.
|
||||||
|
(g_quark_from_string): get the associated quark for a string, if there
|
||||||
|
isn't currently a GQuark associated with this string, then allocate a
|
||||||
|
new quark and return that.
|
||||||
|
(g_quark_from_static_string): like the above function, but the string
|
||||||
|
isn't strdup()ed to save memory.
|
||||||
|
(g_quark_to_string): get the string that is associated with a certain
|
||||||
|
GQuark.
|
||||||
|
|
||||||
|
* gdataset.c (g_dataset_id_set_data_full): invoke the destroy function
|
||||||
|
_after_ the new data has been setup.
|
||||||
|
|
||||||
Thu Jun 18 02:35:21 1998 Owen Taylor <otaylor@gtk.org>
|
Thu Jun 18 02:35:21 1998 Owen Taylor <otaylor@gtk.org>
|
||||||
|
|
||||||
* glib.h: Changed messages for g_return_[val]_if_fail to
|
* glib.h: Changed messages for g_return_[val]_if_fail to
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
Fri Jun 19 03:11:02 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* gdataset.c: removed g_dataset_try_key, g_dataset_force_id and
|
||||||
|
g_dataset_retrive_key in favour of GQuarks.
|
||||||
|
a GQuark is an numeric id wich is associated with a certain string.
|
||||||
|
(g_quark_try_string): try to get the quark associated with this string,
|
||||||
|
if the lookup failed return 0.
|
||||||
|
(g_quark_from_string): get the associated quark for a string, if there
|
||||||
|
isn't currently a GQuark associated with this string, then allocate a
|
||||||
|
new quark and return that.
|
||||||
|
(g_quark_from_static_string): like the above function, but the string
|
||||||
|
isn't strdup()ed to save memory.
|
||||||
|
(g_quark_to_string): get the string that is associated with a certain
|
||||||
|
GQuark.
|
||||||
|
|
||||||
|
* gdataset.c (g_dataset_id_set_data_full): invoke the destroy function
|
||||||
|
_after_ the new data has been setup.
|
||||||
|
|
||||||
Thu Jun 18 02:35:21 1998 Owen Taylor <otaylor@gtk.org>
|
Thu Jun 18 02:35:21 1998 Owen Taylor <otaylor@gtk.org>
|
||||||
|
|
||||||
* glib.h: Changed messages for g_return_[val]_if_fail to
|
* glib.h: Changed messages for g_return_[val]_if_fail to
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
Fri Jun 19 03:11:02 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* gdataset.c: removed g_dataset_try_key, g_dataset_force_id and
|
||||||
|
g_dataset_retrive_key in favour of GQuarks.
|
||||||
|
a GQuark is an numeric id wich is associated with a certain string.
|
||||||
|
(g_quark_try_string): try to get the quark associated with this string,
|
||||||
|
if the lookup failed return 0.
|
||||||
|
(g_quark_from_string): get the associated quark for a string, if there
|
||||||
|
isn't currently a GQuark associated with this string, then allocate a
|
||||||
|
new quark and return that.
|
||||||
|
(g_quark_from_static_string): like the above function, but the string
|
||||||
|
isn't strdup()ed to save memory.
|
||||||
|
(g_quark_to_string): get the string that is associated with a certain
|
||||||
|
GQuark.
|
||||||
|
|
||||||
|
* gdataset.c (g_dataset_id_set_data_full): invoke the destroy function
|
||||||
|
_after_ the new data has been setup.
|
||||||
|
|
||||||
Thu Jun 18 02:35:21 1998 Owen Taylor <otaylor@gtk.org>
|
Thu Jun 18 02:35:21 1998 Owen Taylor <otaylor@gtk.org>
|
||||||
|
|
||||||
* glib.h: Changed messages for g_return_[val]_if_fail to
|
* glib.h: Changed messages for g_return_[val]_if_fail to
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
Fri Jun 19 03:11:02 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* gdataset.c: removed g_dataset_try_key, g_dataset_force_id and
|
||||||
|
g_dataset_retrive_key in favour of GQuarks.
|
||||||
|
a GQuark is an numeric id wich is associated with a certain string.
|
||||||
|
(g_quark_try_string): try to get the quark associated with this string,
|
||||||
|
if the lookup failed return 0.
|
||||||
|
(g_quark_from_string): get the associated quark for a string, if there
|
||||||
|
isn't currently a GQuark associated with this string, then allocate a
|
||||||
|
new quark and return that.
|
||||||
|
(g_quark_from_static_string): like the above function, but the string
|
||||||
|
isn't strdup()ed to save memory.
|
||||||
|
(g_quark_to_string): get the string that is associated with a certain
|
||||||
|
GQuark.
|
||||||
|
|
||||||
|
* gdataset.c (g_dataset_id_set_data_full): invoke the destroy function
|
||||||
|
_after_ the new data has been setup.
|
||||||
|
|
||||||
Thu Jun 18 02:35:21 1998 Owen Taylor <otaylor@gtk.org>
|
Thu Jun 18 02:35:21 1998 Owen Taylor <otaylor@gtk.org>
|
||||||
|
|
||||||
* glib.h: Changed messages for g_return_[val]_if_fail to
|
* glib.h: Changed messages for g_return_[val]_if_fail to
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
Fri Jun 19 03:11:02 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* gdataset.c: removed g_dataset_try_key, g_dataset_force_id and
|
||||||
|
g_dataset_retrive_key in favour of GQuarks.
|
||||||
|
a GQuark is an numeric id wich is associated with a certain string.
|
||||||
|
(g_quark_try_string): try to get the quark associated with this string,
|
||||||
|
if the lookup failed return 0.
|
||||||
|
(g_quark_from_string): get the associated quark for a string, if there
|
||||||
|
isn't currently a GQuark associated with this string, then allocate a
|
||||||
|
new quark and return that.
|
||||||
|
(g_quark_from_static_string): like the above function, but the string
|
||||||
|
isn't strdup()ed to save memory.
|
||||||
|
(g_quark_to_string): get the string that is associated with a certain
|
||||||
|
GQuark.
|
||||||
|
|
||||||
|
* gdataset.c (g_dataset_id_set_data_full): invoke the destroy function
|
||||||
|
_after_ the new data has been setup.
|
||||||
|
|
||||||
Thu Jun 18 02:35:21 1998 Owen Taylor <otaylor@gtk.org>
|
Thu Jun 18 02:35:21 1998 Owen Taylor <otaylor@gtk.org>
|
||||||
|
|
||||||
* glib.h: Changed messages for g_return_[val]_if_fail to
|
* glib.h: Changed messages for g_return_[val]_if_fail to
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
Fri Jun 19 03:11:02 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* gdataset.c: removed g_dataset_try_key, g_dataset_force_id and
|
||||||
|
g_dataset_retrive_key in favour of GQuarks.
|
||||||
|
a GQuark is an numeric id wich is associated with a certain string.
|
||||||
|
(g_quark_try_string): try to get the quark associated with this string,
|
||||||
|
if the lookup failed return 0.
|
||||||
|
(g_quark_from_string): get the associated quark for a string, if there
|
||||||
|
isn't currently a GQuark associated with this string, then allocate a
|
||||||
|
new quark and return that.
|
||||||
|
(g_quark_from_static_string): like the above function, but the string
|
||||||
|
isn't strdup()ed to save memory.
|
||||||
|
(g_quark_to_string): get the string that is associated with a certain
|
||||||
|
GQuark.
|
||||||
|
|
||||||
|
* gdataset.c (g_dataset_id_set_data_full): invoke the destroy function
|
||||||
|
_after_ the new data has been setup.
|
||||||
|
|
||||||
Thu Jun 18 02:35:21 1998 Owen Taylor <otaylor@gtk.org>
|
Thu Jun 18 02:35:21 1998 Owen Taylor <otaylor@gtk.org>
|
||||||
|
|
||||||
* glib.h: Changed messages for g_return_[val]_if_fail to
|
* glib.h: Changed messages for g_return_[val]_if_fail to
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
Fri Jun 19 03:11:02 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* gdataset.c: removed g_dataset_try_key, g_dataset_force_id and
|
||||||
|
g_dataset_retrive_key in favour of GQuarks.
|
||||||
|
a GQuark is an numeric id wich is associated with a certain string.
|
||||||
|
(g_quark_try_string): try to get the quark associated with this string,
|
||||||
|
if the lookup failed return 0.
|
||||||
|
(g_quark_from_string): get the associated quark for a string, if there
|
||||||
|
isn't currently a GQuark associated with this string, then allocate a
|
||||||
|
new quark and return that.
|
||||||
|
(g_quark_from_static_string): like the above function, but the string
|
||||||
|
isn't strdup()ed to save memory.
|
||||||
|
(g_quark_to_string): get the string that is associated with a certain
|
||||||
|
GQuark.
|
||||||
|
|
||||||
|
* gdataset.c (g_dataset_id_set_data_full): invoke the destroy function
|
||||||
|
_after_ the new data has been setup.
|
||||||
|
|
||||||
Thu Jun 18 02:35:21 1998 Owen Taylor <otaylor@gtk.org>
|
Thu Jun 18 02:35:21 1998 Owen Taylor <otaylor@gtk.org>
|
||||||
|
|
||||||
* glib.h: Changed messages for g_return_[val]_if_fail to
|
* glib.h: Changed messages for g_return_[val]_if_fail to
|
||||||
|
167
gdataset.c
167
gdataset.c
@ -51,19 +51,17 @@ 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 void g_dataset_alloc_key (const gchar *string,
|
static inline GQuark g_quark_new (const gchar *string);
|
||||||
guint **id,
|
|
||||||
gchar **key);
|
|
||||||
|
|
||||||
|
|
||||||
/* --- variables --- */
|
/* --- variables --- */
|
||||||
|
static GHashTable *g_quark_ht = NULL;
|
||||||
|
static gchar **g_quarks = NULL;
|
||||||
|
static GQuark g_quark_seq_id = 0;
|
||||||
static GHashTable *g_dataset_location_ht = NULL;
|
static GHashTable *g_dataset_location_ht = NULL;
|
||||||
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 gchar **g_dataset_key_array = NULL;
|
|
||||||
static guint g_dataset_seq_id = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -126,7 +124,7 @@ g_dataset_destroy (gconstpointer dataset_location)
|
|||||||
|
|
||||||
void
|
void
|
||||||
g_dataset_id_set_destroy (gconstpointer dataset_location,
|
g_dataset_id_set_destroy (gconstpointer dataset_location,
|
||||||
guint key_id,
|
GQuark key_id,
|
||||||
GDestroyNotify destroy_func)
|
GDestroyNotify destroy_func)
|
||||||
{
|
{
|
||||||
g_return_if_fail (dataset_location != NULL);
|
g_return_if_fail (dataset_location != NULL);
|
||||||
@ -155,7 +153,7 @@ g_dataset_id_set_destroy (gconstpointer dataset_location,
|
|||||||
|
|
||||||
gpointer
|
gpointer
|
||||||
g_dataset_id_get_data (gconstpointer dataset_location,
|
g_dataset_id_get_data (gconstpointer dataset_location,
|
||||||
guint key_id)
|
GQuark key_id)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (dataset_location != NULL, NULL);
|
g_return_val_if_fail (dataset_location != NULL, NULL);
|
||||||
|
|
||||||
@ -179,7 +177,7 @@ g_dataset_id_get_data (gconstpointer dataset_location,
|
|||||||
|
|
||||||
void
|
void
|
||||||
g_dataset_id_set_data_full (gconstpointer dataset_location,
|
g_dataset_id_set_data_full (gconstpointer dataset_location,
|
||||||
guint key_id,
|
GQuark key_id,
|
||||||
gpointer data,
|
gpointer data,
|
||||||
GDestroyNotify destroy_func)
|
GDestroyNotify destroy_func)
|
||||||
{
|
{
|
||||||
@ -226,7 +224,8 @@ g_dataset_id_set_data_full (gconstpointer dataset_location,
|
|||||||
list->destroy_func (list->data);
|
list->destroy_func (list->data);
|
||||||
|
|
||||||
g_mem_chunk_free (g_dataset_data_mem_chunk, list);
|
g_mem_chunk_free (g_dataset_data_mem_chunk, list);
|
||||||
break;
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
prev = list;
|
prev = list;
|
||||||
@ -235,31 +234,30 @@ g_dataset_id_set_data_full (gconstpointer dataset_location,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
register GDatasetData *prev;
|
|
||||||
|
|
||||||
prev = NULL;
|
|
||||||
while (list)
|
while (list)
|
||||||
{
|
{
|
||||||
if (list->id == key_id)
|
if (list->id == key_id)
|
||||||
{
|
{
|
||||||
if (prev)
|
register GDestroyNotify dfunc;
|
||||||
prev->next = list->next;
|
register gpointer ddata;
|
||||||
else
|
|
||||||
dataset->data_list = list->next;
|
|
||||||
|
|
||||||
/* we need to have unlinked before invoking the destroy function
|
dfunc = list->destroy_func;
|
||||||
|
ddata = list->data;
|
||||||
|
list->data = data;
|
||||||
|
list->destroy_func = destroy_func;
|
||||||
|
|
||||||
|
/* we need to have updated all structures prior to
|
||||||
|
* invokation of the destroy function
|
||||||
*/
|
*/
|
||||||
if (list->destroy_func)
|
if (dfunc)
|
||||||
list->destroy_func (list->data);
|
dfunc (ddata);
|
||||||
|
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
prev = list;
|
|
||||||
list = list->next;
|
list = list->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!list)
|
|
||||||
list = g_chunk_new (GDatasetData, g_dataset_data_mem_chunk);
|
list = g_chunk_new (GDatasetData, g_dataset_data_mem_chunk);
|
||||||
list->next = dataset->data_list;
|
list->next = dataset->data_list;
|
||||||
list->id = key_id;
|
list->id = key_id;
|
||||||
@ -269,52 +267,13 @@ g_dataset_id_set_data_full (gconstpointer dataset_location,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
guint
|
|
||||||
g_dataset_try_key (const gchar *key)
|
|
||||||
{
|
|
||||||
register guint *id;
|
|
||||||
g_return_val_if_fail (key != NULL, 0);
|
|
||||||
|
|
||||||
if (g_dataset_key_ht)
|
|
||||||
{
|
|
||||||
id = g_hash_table_lookup (g_dataset_key_ht, (gpointer) key);
|
|
||||||
|
|
||||||
if (id)
|
|
||||||
return *id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
guint
|
|
||||||
g_dataset_force_id (const gchar *key)
|
|
||||||
{
|
|
||||||
guint *id;
|
|
||||||
|
|
||||||
g_return_val_if_fail (key != NULL, 0);
|
|
||||||
|
|
||||||
if (!g_dataset_key_ht)
|
|
||||||
g_dataset_initialize ();
|
|
||||||
|
|
||||||
id = g_hash_table_lookup (g_dataset_key_ht, (gpointer) key);
|
|
||||||
if (!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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_dataset_initialize (void)
|
g_dataset_initialize (void)
|
||||||
{
|
{
|
||||||
if (!g_dataset_location_ht)
|
if (!g_dataset_location_ht)
|
||||||
{
|
{
|
||||||
|
g_quark_ht = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
g_dataset_location_ht = g_hash_table_new (g_direct_hash, NULL);
|
g_dataset_location_ht = g_hash_table_new (g_direct_hash, NULL);
|
||||||
g_dataset_key_ht = g_hash_table_new (g_str_hash, g_str_equal);
|
|
||||||
g_dataset_cached = NULL;
|
g_dataset_cached = NULL;
|
||||||
g_dataset_mem_chunk =
|
g_dataset_mem_chunk =
|
||||||
g_mem_chunk_new ("GDataset MemChunk",
|
g_mem_chunk_new ("GDataset MemChunk",
|
||||||
@ -329,28 +288,74 @@ g_dataset_initialize (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar*
|
GQuark
|
||||||
g_dataset_retrive_key (guint id)
|
g_quark_try_string (const gchar *string)
|
||||||
{
|
{
|
||||||
if (id > 0 && id <= g_dataset_seq_id)
|
g_return_val_if_fail (string != NULL, 0);
|
||||||
return g_dataset_key_array[id - 1];
|
|
||||||
|
if (g_quark_ht)
|
||||||
|
return (gulong) g_hash_table_lookup (g_quark_ht, string);
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
GQuark
|
||||||
|
g_quark_from_string (const gchar *string)
|
||||||
|
{
|
||||||
|
GQuark quark;
|
||||||
|
|
||||||
|
g_return_val_if_fail (string != NULL, 0);
|
||||||
|
|
||||||
|
if (!g_quark_ht)
|
||||||
|
g_dataset_initialize ();
|
||||||
|
|
||||||
|
quark = (gulong) g_hash_table_lookup (g_quark_ht, string);
|
||||||
|
if (!quark)
|
||||||
|
quark = g_quark_new (g_strdup (string));
|
||||||
|
|
||||||
|
return quark;
|
||||||
|
}
|
||||||
|
|
||||||
|
GQuark
|
||||||
|
g_quark_from_static_string (const gchar *string)
|
||||||
|
{
|
||||||
|
GQuark quark;
|
||||||
|
|
||||||
|
g_return_val_if_fail (string != NULL, 0);
|
||||||
|
|
||||||
|
if (!g_quark_ht)
|
||||||
|
g_dataset_initialize ();
|
||||||
|
|
||||||
|
quark = (gulong) g_hash_table_lookup (g_quark_ht, string);
|
||||||
|
if (!quark)
|
||||||
|
quark = g_quark_new (string);
|
||||||
|
|
||||||
|
return quark;
|
||||||
|
}
|
||||||
|
|
||||||
|
gchar*
|
||||||
|
g_quark_to_string (GQuark quark)
|
||||||
|
{
|
||||||
|
if (quark > 0 && quark <= g_quark_seq_id)
|
||||||
|
return g_quarks[quark - 1];
|
||||||
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static inline GQuark
|
||||||
g_dataset_alloc_key (const gchar *string,
|
g_quark_new (const gchar *string)
|
||||||
guint **id,
|
|
||||||
gchar **key)
|
|
||||||
{
|
{
|
||||||
if (g_dataset_seq_id % G_DATASET_BLOCK_SIZE == 0)
|
GQuark quark;
|
||||||
g_dataset_key_array = g_realloc (g_dataset_key_array,
|
|
||||||
(g_dataset_seq_id + G_DATASET_BLOCK_SIZE) * sizeof (gchar*));
|
|
||||||
|
|
||||||
*key = g_new (gchar, sizeof (guint) + strlen (string) + 1);
|
if (g_quark_seq_id % G_DATASET_BLOCK_SIZE == 0)
|
||||||
*id = (guint*) *key;
|
g_quarks = g_realloc (g_quarks,
|
||||||
*key += sizeof (guint);
|
(g_quark_seq_id + G_DATASET_BLOCK_SIZE) * sizeof (gchar*));
|
||||||
strcpy (*key, string);
|
|
||||||
g_dataset_key_array[g_dataset_seq_id] = *key;
|
|
||||||
g_dataset_seq_id++;
|
g_quarks[g_quark_seq_id] = (gchar*) string;
|
||||||
**id = g_dataset_seq_id;
|
g_quark_seq_id++;
|
||||||
|
quark = g_quark_seq_id;
|
||||||
|
g_hash_table_insert (g_quark_ht, (gchar*) string, GUINT_TO_POINTER (quark));
|
||||||
|
|
||||||
|
return quark;
|
||||||
}
|
}
|
||||||
|
23
glib.h
23
glib.h
@ -436,7 +436,7 @@ typedef unsigned long guint32;
|
|||||||
typedef gint32 gssize;
|
typedef gint32 gssize;
|
||||||
typedef guint32 gsize;
|
typedef guint32 gsize;
|
||||||
typedef gint32 gtime;
|
typedef gint32 gtime;
|
||||||
|
typedef guint32 GQuark;
|
||||||
|
|
||||||
typedef struct _GList GList;
|
typedef struct _GList GList;
|
||||||
typedef struct _GSList GSList;
|
typedef struct _GSList GSList;
|
||||||
@ -975,28 +975,31 @@ gint g_direct_equal (gconstpointer v,
|
|||||||
gconstpointer v2);
|
gconstpointer v2);
|
||||||
|
|
||||||
|
|
||||||
|
/* Quarks (string<->id association)
|
||||||
|
*/
|
||||||
|
GQuark g_quark_try_string (const gchar *string);
|
||||||
|
GQuark g_quark_from_static_string (const gchar *string);
|
||||||
|
GQuark g_quark_from_string (const gchar *string);
|
||||||
|
gchar* g_quark_to_string (GQuark quark);
|
||||||
|
|
||||||
/* Location Associated Data
|
/* Location Associated Data
|
||||||
*/
|
*/
|
||||||
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_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);
|
GQuark key_id);
|
||||||
void g_dataset_id_set_data_full (gconstpointer dataset_location,
|
void g_dataset_id_set_data_full (gconstpointer dataset_location,
|
||||||
guint key_id,
|
GQuark key_id,
|
||||||
gpointer data,
|
gpointer data,
|
||||||
GDestroyNotify destroy_func);
|
GDestroyNotify destroy_func);
|
||||||
void g_dataset_id_set_destroy (gconstpointer dataset_location,
|
void g_dataset_id_set_destroy (gconstpointer dataset_location,
|
||||||
guint key_id,
|
GQuark key_id,
|
||||||
GDestroyNotify destroy_func);
|
GDestroyNotify destroy_func);
|
||||||
|
|
||||||
#define g_dataset_id_set_data(l,k,d) G_STMT_START{g_dataset_id_set_data_full((l),(k),(d),NULL);}G_STMT_END
|
#define g_dataset_id_set_data(l,k,d) G_STMT_START{g_dataset_id_set_data_full((l),(k),(d),NULL);}G_STMT_END
|
||||||
#define g_dataset_id_remove_data(l,k) G_STMT_START{g_dataset_id_set_data((l),(k),NULL);}G_STMT_END
|
#define g_dataset_id_remove_data(l,k) G_STMT_START{g_dataset_id_set_data((l),(k),NULL);}G_STMT_END
|
||||||
#define g_dataset_get_data(l,k) (g_dataset_id_get_data((l),g_dataset_try_key(k)))
|
#define g_dataset_get_data(l,k) (g_dataset_id_get_data((l),g_quark_try_string(k)))
|
||||||
#define g_dataset_set_data_full(l,k,d,f) G_STMT_START{g_dataset_id_set_data_full((l),g_dataset_force_id(k),(d),(f));}G_STMT_END
|
#define g_dataset_set_data_full(l,k,d,f) G_STMT_START{g_dataset_id_set_data_full((l),g_quark_from_string(k),(d),(f));}G_STMT_END
|
||||||
#define g_dataset_set_destroy(l,k,f) G_STMT_START{g_dataset_id_set_destroy((l),g_dataset_force_id(k),(f));}G_STMT_END
|
#define g_dataset_set_destroy(l,k,f) G_STMT_START{g_dataset_id_set_destroy((l),g_quark_from_string(k),(f));}G_STMT_END
|
||||||
#define g_dataset_set_data(l,k,d) G_STMT_START{g_dataset_set_data_full((l),(k),(d),NULL);}G_STMT_END
|
#define g_dataset_set_data(l,k,d) G_STMT_START{g_dataset_set_data_full((l),(k),(d),NULL);}G_STMT_END
|
||||||
#define g_dataset_remove_data(l,k) G_STMT_START{g_dataset_set_data((l),(k),NULL);}G_STMT_END
|
#define g_dataset_remove_data(l,k) G_STMT_START{g_dataset_set_data((l),(k),NULL);}G_STMT_END
|
||||||
|
|
||||||
|
167
glib/gdataset.c
167
glib/gdataset.c
@ -51,19 +51,17 @@ 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 void g_dataset_alloc_key (const gchar *string,
|
static inline GQuark g_quark_new (const gchar *string);
|
||||||
guint **id,
|
|
||||||
gchar **key);
|
|
||||||
|
|
||||||
|
|
||||||
/* --- variables --- */
|
/* --- variables --- */
|
||||||
|
static GHashTable *g_quark_ht = NULL;
|
||||||
|
static gchar **g_quarks = NULL;
|
||||||
|
static GQuark g_quark_seq_id = 0;
|
||||||
static GHashTable *g_dataset_location_ht = NULL;
|
static GHashTable *g_dataset_location_ht = NULL;
|
||||||
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 gchar **g_dataset_key_array = NULL;
|
|
||||||
static guint g_dataset_seq_id = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -126,7 +124,7 @@ g_dataset_destroy (gconstpointer dataset_location)
|
|||||||
|
|
||||||
void
|
void
|
||||||
g_dataset_id_set_destroy (gconstpointer dataset_location,
|
g_dataset_id_set_destroy (gconstpointer dataset_location,
|
||||||
guint key_id,
|
GQuark key_id,
|
||||||
GDestroyNotify destroy_func)
|
GDestroyNotify destroy_func)
|
||||||
{
|
{
|
||||||
g_return_if_fail (dataset_location != NULL);
|
g_return_if_fail (dataset_location != NULL);
|
||||||
@ -155,7 +153,7 @@ g_dataset_id_set_destroy (gconstpointer dataset_location,
|
|||||||
|
|
||||||
gpointer
|
gpointer
|
||||||
g_dataset_id_get_data (gconstpointer dataset_location,
|
g_dataset_id_get_data (gconstpointer dataset_location,
|
||||||
guint key_id)
|
GQuark key_id)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (dataset_location != NULL, NULL);
|
g_return_val_if_fail (dataset_location != NULL, NULL);
|
||||||
|
|
||||||
@ -179,7 +177,7 @@ g_dataset_id_get_data (gconstpointer dataset_location,
|
|||||||
|
|
||||||
void
|
void
|
||||||
g_dataset_id_set_data_full (gconstpointer dataset_location,
|
g_dataset_id_set_data_full (gconstpointer dataset_location,
|
||||||
guint key_id,
|
GQuark key_id,
|
||||||
gpointer data,
|
gpointer data,
|
||||||
GDestroyNotify destroy_func)
|
GDestroyNotify destroy_func)
|
||||||
{
|
{
|
||||||
@ -226,7 +224,8 @@ g_dataset_id_set_data_full (gconstpointer dataset_location,
|
|||||||
list->destroy_func (list->data);
|
list->destroy_func (list->data);
|
||||||
|
|
||||||
g_mem_chunk_free (g_dataset_data_mem_chunk, list);
|
g_mem_chunk_free (g_dataset_data_mem_chunk, list);
|
||||||
break;
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
prev = list;
|
prev = list;
|
||||||
@ -235,31 +234,30 @@ g_dataset_id_set_data_full (gconstpointer dataset_location,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
register GDatasetData *prev;
|
|
||||||
|
|
||||||
prev = NULL;
|
|
||||||
while (list)
|
while (list)
|
||||||
{
|
{
|
||||||
if (list->id == key_id)
|
if (list->id == key_id)
|
||||||
{
|
{
|
||||||
if (prev)
|
register GDestroyNotify dfunc;
|
||||||
prev->next = list->next;
|
register gpointer ddata;
|
||||||
else
|
|
||||||
dataset->data_list = list->next;
|
|
||||||
|
|
||||||
/* we need to have unlinked before invoking the destroy function
|
dfunc = list->destroy_func;
|
||||||
|
ddata = list->data;
|
||||||
|
list->data = data;
|
||||||
|
list->destroy_func = destroy_func;
|
||||||
|
|
||||||
|
/* we need to have updated all structures prior to
|
||||||
|
* invokation of the destroy function
|
||||||
*/
|
*/
|
||||||
if (list->destroy_func)
|
if (dfunc)
|
||||||
list->destroy_func (list->data);
|
dfunc (ddata);
|
||||||
|
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
prev = list;
|
|
||||||
list = list->next;
|
list = list->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!list)
|
|
||||||
list = g_chunk_new (GDatasetData, g_dataset_data_mem_chunk);
|
list = g_chunk_new (GDatasetData, g_dataset_data_mem_chunk);
|
||||||
list->next = dataset->data_list;
|
list->next = dataset->data_list;
|
||||||
list->id = key_id;
|
list->id = key_id;
|
||||||
@ -269,52 +267,13 @@ g_dataset_id_set_data_full (gconstpointer dataset_location,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
guint
|
|
||||||
g_dataset_try_key (const gchar *key)
|
|
||||||
{
|
|
||||||
register guint *id;
|
|
||||||
g_return_val_if_fail (key != NULL, 0);
|
|
||||||
|
|
||||||
if (g_dataset_key_ht)
|
|
||||||
{
|
|
||||||
id = g_hash_table_lookup (g_dataset_key_ht, (gpointer) key);
|
|
||||||
|
|
||||||
if (id)
|
|
||||||
return *id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
guint
|
|
||||||
g_dataset_force_id (const gchar *key)
|
|
||||||
{
|
|
||||||
guint *id;
|
|
||||||
|
|
||||||
g_return_val_if_fail (key != NULL, 0);
|
|
||||||
|
|
||||||
if (!g_dataset_key_ht)
|
|
||||||
g_dataset_initialize ();
|
|
||||||
|
|
||||||
id = g_hash_table_lookup (g_dataset_key_ht, (gpointer) key);
|
|
||||||
if (!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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_dataset_initialize (void)
|
g_dataset_initialize (void)
|
||||||
{
|
{
|
||||||
if (!g_dataset_location_ht)
|
if (!g_dataset_location_ht)
|
||||||
{
|
{
|
||||||
|
g_quark_ht = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
g_dataset_location_ht = g_hash_table_new (g_direct_hash, NULL);
|
g_dataset_location_ht = g_hash_table_new (g_direct_hash, NULL);
|
||||||
g_dataset_key_ht = g_hash_table_new (g_str_hash, g_str_equal);
|
|
||||||
g_dataset_cached = NULL;
|
g_dataset_cached = NULL;
|
||||||
g_dataset_mem_chunk =
|
g_dataset_mem_chunk =
|
||||||
g_mem_chunk_new ("GDataset MemChunk",
|
g_mem_chunk_new ("GDataset MemChunk",
|
||||||
@ -329,28 +288,74 @@ g_dataset_initialize (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar*
|
GQuark
|
||||||
g_dataset_retrive_key (guint id)
|
g_quark_try_string (const gchar *string)
|
||||||
{
|
{
|
||||||
if (id > 0 && id <= g_dataset_seq_id)
|
g_return_val_if_fail (string != NULL, 0);
|
||||||
return g_dataset_key_array[id - 1];
|
|
||||||
|
if (g_quark_ht)
|
||||||
|
return (gulong) g_hash_table_lookup (g_quark_ht, string);
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
GQuark
|
||||||
|
g_quark_from_string (const gchar *string)
|
||||||
|
{
|
||||||
|
GQuark quark;
|
||||||
|
|
||||||
|
g_return_val_if_fail (string != NULL, 0);
|
||||||
|
|
||||||
|
if (!g_quark_ht)
|
||||||
|
g_dataset_initialize ();
|
||||||
|
|
||||||
|
quark = (gulong) g_hash_table_lookup (g_quark_ht, string);
|
||||||
|
if (!quark)
|
||||||
|
quark = g_quark_new (g_strdup (string));
|
||||||
|
|
||||||
|
return quark;
|
||||||
|
}
|
||||||
|
|
||||||
|
GQuark
|
||||||
|
g_quark_from_static_string (const gchar *string)
|
||||||
|
{
|
||||||
|
GQuark quark;
|
||||||
|
|
||||||
|
g_return_val_if_fail (string != NULL, 0);
|
||||||
|
|
||||||
|
if (!g_quark_ht)
|
||||||
|
g_dataset_initialize ();
|
||||||
|
|
||||||
|
quark = (gulong) g_hash_table_lookup (g_quark_ht, string);
|
||||||
|
if (!quark)
|
||||||
|
quark = g_quark_new (string);
|
||||||
|
|
||||||
|
return quark;
|
||||||
|
}
|
||||||
|
|
||||||
|
gchar*
|
||||||
|
g_quark_to_string (GQuark quark)
|
||||||
|
{
|
||||||
|
if (quark > 0 && quark <= g_quark_seq_id)
|
||||||
|
return g_quarks[quark - 1];
|
||||||
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static inline GQuark
|
||||||
g_dataset_alloc_key (const gchar *string,
|
g_quark_new (const gchar *string)
|
||||||
guint **id,
|
|
||||||
gchar **key)
|
|
||||||
{
|
{
|
||||||
if (g_dataset_seq_id % G_DATASET_BLOCK_SIZE == 0)
|
GQuark quark;
|
||||||
g_dataset_key_array = g_realloc (g_dataset_key_array,
|
|
||||||
(g_dataset_seq_id + G_DATASET_BLOCK_SIZE) * sizeof (gchar*));
|
|
||||||
|
|
||||||
*key = g_new (gchar, sizeof (guint) + strlen (string) + 1);
|
if (g_quark_seq_id % G_DATASET_BLOCK_SIZE == 0)
|
||||||
*id = (guint*) *key;
|
g_quarks = g_realloc (g_quarks,
|
||||||
*key += sizeof (guint);
|
(g_quark_seq_id + G_DATASET_BLOCK_SIZE) * sizeof (gchar*));
|
||||||
strcpy (*key, string);
|
|
||||||
g_dataset_key_array[g_dataset_seq_id] = *key;
|
|
||||||
g_dataset_seq_id++;
|
g_quarks[g_quark_seq_id] = (gchar*) string;
|
||||||
**id = g_dataset_seq_id;
|
g_quark_seq_id++;
|
||||||
|
quark = g_quark_seq_id;
|
||||||
|
g_hash_table_insert (g_quark_ht, (gchar*) string, GUINT_TO_POINTER (quark));
|
||||||
|
|
||||||
|
return quark;
|
||||||
}
|
}
|
||||||
|
23
glib/glib.h
23
glib/glib.h
@ -436,7 +436,7 @@ typedef unsigned long guint32;
|
|||||||
typedef gint32 gssize;
|
typedef gint32 gssize;
|
||||||
typedef guint32 gsize;
|
typedef guint32 gsize;
|
||||||
typedef gint32 gtime;
|
typedef gint32 gtime;
|
||||||
|
typedef guint32 GQuark;
|
||||||
|
|
||||||
typedef struct _GList GList;
|
typedef struct _GList GList;
|
||||||
typedef struct _GSList GSList;
|
typedef struct _GSList GSList;
|
||||||
@ -975,28 +975,31 @@ gint g_direct_equal (gconstpointer v,
|
|||||||
gconstpointer v2);
|
gconstpointer v2);
|
||||||
|
|
||||||
|
|
||||||
|
/* Quarks (string<->id association)
|
||||||
|
*/
|
||||||
|
GQuark g_quark_try_string (const gchar *string);
|
||||||
|
GQuark g_quark_from_static_string (const gchar *string);
|
||||||
|
GQuark g_quark_from_string (const gchar *string);
|
||||||
|
gchar* g_quark_to_string (GQuark quark);
|
||||||
|
|
||||||
/* Location Associated Data
|
/* Location Associated Data
|
||||||
*/
|
*/
|
||||||
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_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);
|
GQuark key_id);
|
||||||
void g_dataset_id_set_data_full (gconstpointer dataset_location,
|
void g_dataset_id_set_data_full (gconstpointer dataset_location,
|
||||||
guint key_id,
|
GQuark key_id,
|
||||||
gpointer data,
|
gpointer data,
|
||||||
GDestroyNotify destroy_func);
|
GDestroyNotify destroy_func);
|
||||||
void g_dataset_id_set_destroy (gconstpointer dataset_location,
|
void g_dataset_id_set_destroy (gconstpointer dataset_location,
|
||||||
guint key_id,
|
GQuark key_id,
|
||||||
GDestroyNotify destroy_func);
|
GDestroyNotify destroy_func);
|
||||||
|
|
||||||
#define g_dataset_id_set_data(l,k,d) G_STMT_START{g_dataset_id_set_data_full((l),(k),(d),NULL);}G_STMT_END
|
#define g_dataset_id_set_data(l,k,d) G_STMT_START{g_dataset_id_set_data_full((l),(k),(d),NULL);}G_STMT_END
|
||||||
#define g_dataset_id_remove_data(l,k) G_STMT_START{g_dataset_id_set_data((l),(k),NULL);}G_STMT_END
|
#define g_dataset_id_remove_data(l,k) G_STMT_START{g_dataset_id_set_data((l),(k),NULL);}G_STMT_END
|
||||||
#define g_dataset_get_data(l,k) (g_dataset_id_get_data((l),g_dataset_try_key(k)))
|
#define g_dataset_get_data(l,k) (g_dataset_id_get_data((l),g_quark_try_string(k)))
|
||||||
#define g_dataset_set_data_full(l,k,d,f) G_STMT_START{g_dataset_id_set_data_full((l),g_dataset_force_id(k),(d),(f));}G_STMT_END
|
#define g_dataset_set_data_full(l,k,d,f) G_STMT_START{g_dataset_id_set_data_full((l),g_quark_from_string(k),(d),(f));}G_STMT_END
|
||||||
#define g_dataset_set_destroy(l,k,f) G_STMT_START{g_dataset_id_set_destroy((l),g_dataset_force_id(k),(f));}G_STMT_END
|
#define g_dataset_set_destroy(l,k,f) G_STMT_START{g_dataset_id_set_destroy((l),g_quark_from_string(k),(f));}G_STMT_END
|
||||||
#define g_dataset_set_data(l,k,d) G_STMT_START{g_dataset_set_data_full((l),(k),(d),NULL);}G_STMT_END
|
#define g_dataset_set_data(l,k,d) G_STMT_START{g_dataset_set_data_full((l),(k),(d),NULL);}G_STMT_END
|
||||||
#define g_dataset_remove_data(l,k) G_STMT_START{g_dataset_set_data((l),(k),NULL);}G_STMT_END
|
#define g_dataset_remove_data(l,k) G_STMT_START{g_dataset_set_data((l),(k),NULL);}G_STMT_END
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user