Commit 3ee05ef3 authored by Timm Bäder's avatar Timm Bäder 🤔
Browse files

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.
parent 03ca8758
......@@ -633,7 +633,7 @@ g_key_file_init (GKeyFile *key_file)
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->start_group = NULL;
key_file->parse_buffer = g_string_sized_new (128);
key_file->parse_buffer = NULL;
key_file->list_separator = ';';
key_file->flags = 0;
}
......@@ -1473,6 +1473,9 @@ g_key_file_parse_data (GKeyFile *key_file,
parse_error = NULL;
if (!key_file->parse_buffer)
key_file->parse_buffer = g_string_sized_new (128);
i = 0;
while (i < length)
{
......@@ -1529,6 +1532,9 @@ g_key_file_flush_parse_buffer (GKeyFile *key_file,
g_return_if_fail (key_file != NULL);
if (!key_file->parse_buffer)
return;
file_error = NULL;
if (key_file->parse_buffer->len > 0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment