mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-25 03:32:12 +01:00
keyfile: avoid needless allocations on file load
When loading a key file, the keys and values of individual lines are allocated once when copied and trimmed from the parse buffer and allocated/copied again when added to the lookup map. This commit avoids the second pair of allocations by introducing a new function g_key_file_add_key_value_pair that gives the lookup map direct ownership of the key and value copied from the parse buffer. https://bugzilla.gnome.org/show_bug.cgi?id=650211
This commit is contained in:
parent
8e5f5d40b7
commit
7cb768f890
@ -139,6 +139,9 @@ static void g_key_file_remove_key_value_pair_node (GKeyFile
|
|||||||
GKeyFileGroup *group,
|
GKeyFileGroup *group,
|
||||||
GList *pair_node);
|
GList *pair_node);
|
||||||
|
|
||||||
|
static void g_key_file_add_key_value_pair (GKeyFile *key_file,
|
||||||
|
GKeyFileGroup *group,
|
||||||
|
GKeyFileKeyValuePair *pair);
|
||||||
static void g_key_file_add_key (GKeyFile *key_file,
|
static void g_key_file_add_key (GKeyFile *key_file,
|
||||||
GKeyFileGroup *group,
|
GKeyFileGroup *group,
|
||||||
const gchar *key,
|
const gchar *key,
|
||||||
@ -912,11 +915,22 @@ g_key_file_parse_key_value_pair (GKeyFile *key_file,
|
|||||||
locale = key_get_locale (key);
|
locale = key_get_locale (key);
|
||||||
|
|
||||||
if (locale == NULL || g_key_file_locale_is_interesting (key_file, locale))
|
if (locale == NULL || g_key_file_locale_is_interesting (key_file, locale))
|
||||||
g_key_file_add_key (key_file, key_file->current_group, key, value);
|
{
|
||||||
|
GKeyFileKeyValuePair *pair;
|
||||||
|
|
||||||
|
pair = g_slice_new (GKeyFileKeyValuePair);
|
||||||
|
pair->key = key;
|
||||||
|
pair->value = value;
|
||||||
|
|
||||||
|
g_key_file_add_key_value_pair (key_file, key_file->current_group, pair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_free (key);
|
||||||
|
g_free (value);
|
||||||
|
}
|
||||||
|
|
||||||
g_free (locale);
|
g_free (locale);
|
||||||
g_free (key);
|
|
||||||
g_free (value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar *
|
static gchar *
|
||||||
@ -3329,6 +3343,17 @@ g_key_file_remove_group (GKeyFile *key_file,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
g_key_file_add_key_value_pair (GKeyFile *key_file,
|
||||||
|
GKeyFileGroup *group,
|
||||||
|
GKeyFileKeyValuePair *pair)
|
||||||
|
{
|
||||||
|
g_hash_table_replace (group->lookup_map, pair->key, pair);
|
||||||
|
group->key_value_pairs = g_list_prepend (group->key_value_pairs, pair);
|
||||||
|
group->has_trailing_blank_line = FALSE;
|
||||||
|
key_file->approximate_size += strlen (pair->key) + strlen (pair->value) + 2;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_key_file_add_key (GKeyFile *key_file,
|
g_key_file_add_key (GKeyFile *key_file,
|
||||||
GKeyFileGroup *group,
|
GKeyFileGroup *group,
|
||||||
@ -3341,10 +3366,7 @@ g_key_file_add_key (GKeyFile *key_file,
|
|||||||
pair->key = g_strdup (key);
|
pair->key = g_strdup (key);
|
||||||
pair->value = g_strdup (value);
|
pair->value = g_strdup (value);
|
||||||
|
|
||||||
g_hash_table_replace (group->lookup_map, pair->key, pair);
|
g_key_file_add_key_value_pair (key_file, group, pair);
|
||||||
group->key_value_pairs = g_list_prepend (group->key_value_pairs, pair);
|
|
||||||
group->has_trailing_blank_line = FALSE;
|
|
||||||
key_file->approximate_size += strlen (key) + strlen (value) + 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user