mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
keyfile: fill parse buffer in line sized chunks
When loading a keyfile the incoming bytes are fed to a line buffer to get parsed each time a new line is encountered. The code that fills the line buffer does it inefficiently, one byte at a time. This commit changes that code to look ahead at the incoming bytes for the next '\n' character and then fill the line buffer all at once. https://bugzilla.gnome.org/show_bug.cgi?id=650211
This commit is contained in:
parent
9c1a44cf32
commit
aeac5de2f8
@ -963,7 +963,8 @@ g_key_file_parse_data (GKeyFile *key_file,
|
||||
|
||||
parse_error = NULL;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
i = 0;
|
||||
while (i < length)
|
||||
{
|
||||
if (data[i] == '\n')
|
||||
{
|
||||
@ -988,9 +989,25 @@ g_key_file_parse_data (GKeyFile *key_file,
|
||||
g_propagate_error (error, parse_error);
|
||||
return;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
else
|
||||
g_string_append_c (key_file->parse_buffer, data[i]);
|
||||
{
|
||||
const gchar *start_of_line;
|
||||
const gchar *end_of_line;
|
||||
gsize line_length;
|
||||
|
||||
start_of_line = data + i;
|
||||
end_of_line = memchr (start_of_line, '\n', length - i);
|
||||
|
||||
if (end_of_line == NULL)
|
||||
end_of_line = data + length;
|
||||
|
||||
line_length = end_of_line - start_of_line;
|
||||
|
||||
g_string_append_len (key_file->parse_buffer, start_of_line, line_length);
|
||||
i += line_length;
|
||||
}
|
||||
}
|
||||
|
||||
key_file->approximate_size += length;
|
||||
|
Loading…
Reference in New Issue
Block a user