[glib/glib-2-28] keyfile: fill parse buffer in line sized chunks
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-28] keyfile: fill parse buffer in line sized chunks
- Date: Sat, 21 May 2011 04:02:07 +0000 (UTC)
commit 317a249d82340e423b686deca4a6851fa81ce4c2
Author: John Lindgren <john lindgren tds net>
Date: Mon May 16 23:03:30 2011 -0400
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
glib/gkeyfile.c | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c
index 1f462be..31c2a15 100644
--- a/glib/gkeyfile.c
+++ b/glib/gkeyfile.c
@@ -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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]