diff options
author | Emmanuele Bassi <ebassi@openedhand.com> | 2008-05-01 22:58:55 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@openedhand.com> | 2008-05-01 22:58:55 +0100 |
commit | 4c11d0969a44bb70acf6463ef6305999ff443be2 (patch) | |
tree | ea3b3a5be5595cd74c4342334fad608a4a634cbf /json-glib/json-gobject.c | |
parent | 30f9d47ecf43a17610cd9c0074ff832bfa37593c (diff) | |
download | json-glib-4c11d0969a44bb70acf6463ef6305999ff443be2.tar.gz |
Use an array to hold the strings in a vector
Instead of building a GString by concatenating every string inside
an array to deserialize the array into a string vector property,
use a GPtrArray. This is far more efficient (no reallocations are
necessary, as we know the size of the array) and safe (the separator
used to build the string buffer and then split it might exist in
one of the original strings).
Diffstat (limited to 'json-glib/json-gobject.c')
-rw-r--r-- | json-glib/json-gobject.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/json-glib/json-gobject.c b/json-glib/json-gobject.c index b0a0e13..15e9ed5 100644 --- a/json-glib/json-gobject.c +++ b/json-glib/json-gobject.c @@ -189,8 +189,7 @@ json_deserialize_pspec (GValue *value, { JsonArray *array = json_node_get_array (node); guint i, array_len = json_array_get_length (array); - GString *buffer = g_string_new (NULL); - gchar **strv = NULL; + GPtrArray *str_array = g_ptr_array_sized_new (array_len); for (i = 0; i < array_len; i++) { @@ -200,17 +199,13 @@ json_deserialize_pspec (GValue *value, continue; if (json_node_get_string (val) != NULL); - { - g_string_append (buffer, json_node_get_string (val)); - g_string_append_c (buffer, '\v'); - } + g_ptr_array_add (str_array, (gpointer) json_node_get_string (val)); } - strv = g_strsplit (buffer->str, "\v", -1); - g_value_set_boxed (value, strv); + g_value_set_boxed (value, str_array->pdata); + + g_ptr_array_free (str_array, TRUE); - g_strfreev (strv); - g_string_free (buffer, TRUE); retval = TRUE; } break; |