mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 23:16:14 +01:00
keyfile: Don't allocate parse_buffer if we don't need it
When loading a GKeyFile, the sequence is usually: keyfile = g_key_file_new(); g_key_file_load_xxx(keyfile, ...) g_key_file_new() calls g_key_file_init(), which allocates a parse_buffer for parsing. g_key_file_load_xxx() will then g_key_file_clear() the keyfile and call g_key_file_init() again. Just don't allocate a parse_buffer unless we need it for parsing.
This commit is contained in:
parent
03ca87586f
commit
3ee05ef3bd
@ -633,7 +633,7 @@ g_key_file_init (GKeyFile *key_file)
|
|||||||
key_file->groups = g_list_prepend (NULL, key_file->current_group);
|
key_file->groups = g_list_prepend (NULL, key_file->current_group);
|
||||||
key_file->group_hash = g_hash_table_new (g_str_hash, g_str_equal);
|
key_file->group_hash = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
key_file->start_group = NULL;
|
key_file->start_group = NULL;
|
||||||
key_file->parse_buffer = g_string_sized_new (128);
|
key_file->parse_buffer = NULL;
|
||||||
key_file->list_separator = ';';
|
key_file->list_separator = ';';
|
||||||
key_file->flags = 0;
|
key_file->flags = 0;
|
||||||
}
|
}
|
||||||
@ -1473,6 +1473,9 @@ g_key_file_parse_data (GKeyFile *key_file,
|
|||||||
|
|
||||||
parse_error = NULL;
|
parse_error = NULL;
|
||||||
|
|
||||||
|
if (!key_file->parse_buffer)
|
||||||
|
key_file->parse_buffer = g_string_sized_new (128);
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < length)
|
while (i < length)
|
||||||
{
|
{
|
||||||
@ -1529,6 +1532,9 @@ g_key_file_flush_parse_buffer (GKeyFile *key_file,
|
|||||||
|
|
||||||
g_return_if_fail (key_file != NULL);
|
g_return_if_fail (key_file != NULL);
|
||||||
|
|
||||||
|
if (!key_file->parse_buffer)
|
||||||
|
return;
|
||||||
|
|
||||||
file_error = NULL;
|
file_error = NULL;
|
||||||
|
|
||||||
if (key_file->parse_buffer->len > 0)
|
if (key_file->parse_buffer->len > 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user