[librsvg] Save an extra allocation by directly decoding the base64 data into a GByteArray.
- From: Hiroyuki Ikezoe <hiikezoe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Save an extra allocation by directly decoding the base64 data into a GByteArray.
- Date: Sat, 5 Jun 2010 11:33:57 +0000 (UTC)
commit a736624adcacaa5e2ff695b3895104e9a9eab798
Author: Christian Persch <chpe gnome org>
Date: Sat Jun 5 19:28:21 2010 +0900
Save an extra allocation by directly decoding the base64 data into a GByteArray.
Bug #620130.
rsvg-image.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
---
diff --git a/rsvg-image.c b/rsvg-image.c
index dfc9609..d260767 100644
--- a/rsvg-image.c
+++ b/rsvg-image.c
@@ -42,8 +42,9 @@ static GByteArray *
rsvg_acquire_base64_resource (const char *data, GError ** error)
{
GByteArray *array = NULL;
- guchar *bufptr;
- gsize buffer_len;
+ gsize data_len, written_len;
+ int state = 0;
+ guint save = 0;
rsvg_return_val_if_fail (data != NULL, NULL, error);
@@ -51,12 +52,11 @@ rsvg_acquire_base64_resource (const char *data, GError ** error)
if (*data++ == ',')
break;
- bufptr = g_base64_decode (data, &buffer_len);
- if (bufptr) {
- array = g_byte_array_sized_new (buffer_len);
- g_byte_array_append (array, bufptr, buffer_len);
- g_free (bufptr);
- }
+ data_len = strlen (data);
+ array = g_byte_array_sized_new (data_len / 4 * 3);
+ written_len = g_base64_decode_step (data, data_len, array->data,
+ &state, &save);
+ g_byte_array_set_size (array, written_len);
return array;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]