mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-03 17:56:17 +01:00
Merge remote branch 'gvdb/master'
This commit is contained in:
commit
d8ca640422
@ -177,6 +177,14 @@ hash_table_new (gint n_buckets)
|
|||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
hash_table_free (HashTable *table)
|
||||||
|
{
|
||||||
|
g_free (table->buckets);
|
||||||
|
|
||||||
|
g_slice_free (HashTable, table);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
hash_table_insert (gpointer key,
|
hash_table_insert (gpointer key,
|
||||||
gpointer value,
|
gpointer value,
|
||||||
@ -417,6 +425,8 @@ file_builder_add_hash (FileBuilder *fb,
|
|||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hash_table_free (mytable);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FileBuilder *
|
static FileBuilder *
|
||||||
@ -472,6 +482,8 @@ file_builder_serialise (FileBuilder *fb,
|
|||||||
|
|
||||||
g_string_append_len (result, chunk->data, chunk->size);
|
g_string_append_len (result, chunk->data, chunk->size);
|
||||||
g_free (chunk->data);
|
g_free (chunk->data);
|
||||||
|
|
||||||
|
g_slice_free (FileChunk, chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_queue_free (fb->chunks);
|
g_queue_free (fb->chunks);
|
||||||
|
@ -230,7 +230,7 @@ gvdb_table_check_name (GvdbTable *file,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
parent = guint32_from_le (item->parent);
|
parent = guint32_from_le (item->parent);
|
||||||
if (key_length == 0 && parent == -1)
|
if (key_length == 0 && parent == 0xffffffffu)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
if G_LIKELY (parent < file->n_hash_items && this_size > 0)
|
if G_LIKELY (parent < file->n_hash_items && this_size > 0)
|
||||||
@ -340,7 +340,7 @@ gvdb_table_list (GvdbTable *file,
|
|||||||
const guint32_le *list;
|
const guint32_le *list;
|
||||||
gchar **strv;
|
gchar **strv;
|
||||||
guint length;
|
guint length;
|
||||||
gint i;
|
guint i;
|
||||||
|
|
||||||
if ((item = gvdb_table_lookup (file, key, 'L')) == NULL)
|
if ((item = gvdb_table_lookup (file, key, 'L')) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -574,6 +574,30 @@ gvdb_table_is_valid (GvdbTable *table)
|
|||||||
return !!*table->data;
|
return !!*table->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gvdb_table_walk:
|
||||||
|
* @table: a #GvdbTable
|
||||||
|
* @key: a key corresponding to a list
|
||||||
|
* @open_func: the #GvdbWalkOpenFunc
|
||||||
|
* @value_func: the #GvdbWalkValueFunc
|
||||||
|
* @close_func: the #GvdbWalkCloseFunc
|
||||||
|
* @user_data: data to pass to the callbacks
|
||||||
|
*
|
||||||
|
* Looks up the list at @key and iterate over the items in it.
|
||||||
|
*
|
||||||
|
* First, @open_func is called to signal that we are starting to iterate over
|
||||||
|
* the list. Then the list is iterated. When all items in the list have been
|
||||||
|
* iterated over, the @close_func is called.
|
||||||
|
*
|
||||||
|
* When iterating, if a given item in the list is a value then @value_func is
|
||||||
|
* called.
|
||||||
|
*
|
||||||
|
* If a given item in the list is itself a list then @open_func is called. If
|
||||||
|
* that function returns %TRUE then the walk begins iterating the items in the
|
||||||
|
* sublist, until there are no more items, at which point a matching
|
||||||
|
* @close_func call is made. If @open_func returns %FALSE then no iteration of
|
||||||
|
* the sublist occurs and no corresponding @close_func call is made.
|
||||||
|
**/
|
||||||
void
|
void
|
||||||
gvdb_table_walk (GvdbTable *table,
|
gvdb_table_walk (GvdbTable *table,
|
||||||
const gchar *key,
|
const gchar *key,
|
||||||
@ -585,16 +609,18 @@ gvdb_table_walk (GvdbTable *table,
|
|||||||
const struct gvdb_hash_item *item;
|
const struct gvdb_hash_item *item;
|
||||||
const guint32_le *pointers[64];
|
const guint32_le *pointers[64];
|
||||||
const guint32_le *enders[64];
|
const guint32_le *enders[64];
|
||||||
|
gsize name_lengths[64];
|
||||||
gint index = 0;
|
gint index = 0;
|
||||||
|
|
||||||
item = gvdb_table_lookup (table, key, 'L');
|
item = gvdb_table_lookup (table, key, 'L');
|
||||||
|
name_lengths[0] = 0;
|
||||||
pointers[0] = NULL;
|
pointers[0] = NULL;
|
||||||
enders[0] = NULL;
|
enders[0] = NULL;
|
||||||
goto start_here;
|
goto start_here;
|
||||||
|
|
||||||
while (index)
|
while (index)
|
||||||
{
|
{
|
||||||
close_func (user_data);
|
close_func (name_lengths[index], user_data);
|
||||||
index--;
|
index--;
|
||||||
|
|
||||||
while (pointers[index] < enders[index])
|
while (pointers[index] < enders[index])
|
||||||
@ -621,6 +647,7 @@ gvdb_table_walk (GvdbTable *table,
|
|||||||
&pointers[index],
|
&pointers[index],
|
||||||
&length);
|
&length);
|
||||||
enders[index] = pointers[index] + length;
|
enders[index] = pointers[index] + length;
|
||||||
|
name_lengths[index] = name_len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (item->type == 'v')
|
else if (item->type == 'v')
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
typedef struct _GvdbTable GvdbTable;
|
typedef struct _GvdbTable GvdbTable;
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
GvdbTable * gvdb_table_new (const gchar *filename,
|
GvdbTable * gvdb_table_new (const gchar *filename,
|
||||||
gboolean trusted,
|
gboolean trusted,
|
||||||
@ -62,8 +64,10 @@ typedef void (*GvdbWalkValueFunc) (const g
|
|||||||
typedef gboolean (*GvdbWalkOpenFunc) (const gchar *name,
|
typedef gboolean (*GvdbWalkOpenFunc) (const gchar *name,
|
||||||
gsize name_len,
|
gsize name_len,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
typedef void (*GvdbWalkCloseFunc) (gpointer user_data);
|
typedef void (*GvdbWalkCloseFunc) (gsize name_len,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
G_GNUC_INTERNAL
|
||||||
void gvdb_table_walk (GvdbTable *table,
|
void gvdb_table_walk (GvdbTable *table,
|
||||||
const gchar *key,
|
const gchar *key,
|
||||||
GvdbWalkOpenFunc open_func,
|
GvdbWalkOpenFunc open_func,
|
||||||
@ -71,5 +75,6 @@ void gvdb_table_walk (GvdbTab
|
|||||||
GvdbWalkCloseFunc close_func,
|
GvdbWalkCloseFunc close_func,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __gvdb_reader_h__ */
|
#endif /* __gvdb_reader_h__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user