[gcab] trivial: Do not ref the GInputStream in GCabFolder
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcab] trivial: Do not ref the GInputStream in GCabFolder
- Date: Fri, 15 Dec 2017 15:42:51 +0000 (UTC)
commit b06fad69b162a8a44db52a08b764a3175d28af2f
Author: Richard Hughes <richard hughsie com>
Date: Fri Dec 15 09:41:55 2017 +0000
trivial: Do not ref the GInputStream in GCabFolder
Logically the stream is owned by GCabCabinet, and the stream only /used/ by
GCabFolder when decompressing. This also means we only have to create the
GDataInputStream object once when an archive has lots of included folders.
libgcab/gcab-cabinet.c | 8 ++++++--
libgcab/gcab-folder.c | 13 ++-----------
libgcab/gcab-priv.h | 3 ++-
3 files changed, 10 insertions(+), 14 deletions(-)
---
diff --git a/libgcab/gcab-cabinet.c b/libgcab/gcab-cabinet.c
index 346a70f..e4cea35 100644
--- a/libgcab/gcab-cabinet.c
+++ b/libgcab/gcab-cabinet.c
@@ -448,7 +448,7 @@ gcab_cabinet_load (GCabCabinet *self,
cfolder->reserved = NULL;
}
- GCabFolder *folder = gcab_folder_new_steal_cfolder (&cfolder, stream);
+ GCabFolder *folder = gcab_folder_new_steal_cfolder (&cfolder);
if (blob != NULL)
g_object_set (folder, "reserved", blob, NULL);
g_ptr_array_add (self->folders, folder);
@@ -519,9 +519,13 @@ gcab_cabinet_extract (GCabCabinet *self,
return FALSE;
}
+ g_autoptr(GDataInputStream) data = g_data_input_stream_new (self->stream);
+ g_data_input_stream_set_byte_order (data, G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN);
+ g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (data), FALSE);
+
for (guint i = 0; i < self->folders->len; ++i) {
GCabFolder *folder = g_ptr_array_index (self->folders, i);
- if (!gcab_folder_extract (folder, path, self->cheader->res_data,
+ if (!gcab_folder_extract (folder, data, path, self->cheader->res_data,
file_callback, progress_callback, user_data,
cancellable, error)) {
return FALSE;
diff --git a/libgcab/gcab-folder.c b/libgcab/gcab-folder.c
index de15ecf..61bff20 100644
--- a/libgcab/gcab-folder.c
+++ b/libgcab/gcab-folder.c
@@ -54,7 +54,6 @@ struct _GCabFolder
gint comptype;
GByteArray *reserved;
cfolder_t *cfolder;
- GInputStream *stream;
};
enum {
@@ -84,8 +83,6 @@ gcab_folder_finalize (GObject *object)
g_hash_table_unref (self->hash);
if (self->reserved)
g_byte_array_unref (self->reserved);
- if (self->stream)
- g_object_unref (self->stream);
G_OBJECT_CLASS (gcab_folder_parent_class)->finalize (object);
}
@@ -341,15 +338,13 @@ gcab_folder_new (gint comptype)
}
G_GNUC_INTERNAL GCabFolder *
-gcab_folder_new_steal_cfolder (cfolder_t **cfolder, GInputStream *stream)
+gcab_folder_new_steal_cfolder (cfolder_t **cfolder)
{
g_return_val_if_fail (cfolder != NULL, NULL);
- g_return_val_if_fail (G_IS_INPUT_STREAM (stream), NULL);
GCabFolder *self = g_object_new (GCAB_TYPE_FOLDER,
"comptype", (*cfolder)->typecomp,
NULL);
- self->stream = g_object_ref (stream);
self->cfolder = g_steal_pointer (cfolder);
return self;
@@ -382,6 +377,7 @@ sort_by_offset (GCabFile *a, GCabFile *b)
G_GNUC_INTERNAL gboolean
gcab_folder_extract (GCabFolder *self,
+ GDataInputStream *data,
GFile *path,
guint8 res_data,
GCabFileCallback file_callback,
@@ -391,7 +387,6 @@ gcab_folder_extract (GCabFolder *self,
GError **error)
{
GError *my_error = NULL;
- g_autoptr(GDataInputStream) data = NULL;
g_autoptr(GFileOutputStream) out = NULL;
GSList *f = NULL;
g_autoptr(GSList) files = NULL;
@@ -401,10 +396,6 @@ gcab_folder_extract (GCabFolder *self,
/* never loaded from a stream */
g_assert (self->cfolder != NULL);
- data = g_data_input_stream_new (self->stream);
- g_data_input_stream_set_byte_order (data, G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN);
- g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (data), FALSE);
-
if (!g_seekable_seek (G_SEEKABLE (data), self->cfolder->offsetdata, G_SEEK_SET, cancellable, error))
return FALSE;
diff --git a/libgcab/gcab-priv.h b/libgcab/gcab-priv.h
index 0cde13d..4d930ed 100644
--- a/libgcab/gcab-priv.h
+++ b/libgcab/gcab-priv.h
@@ -40,7 +40,7 @@
_GCAB_GET (data, 1, 32, 8) | \
_GCAB_GET (data, 0, 32, 0))
-GCabFolder * gcab_folder_new_steal_cfolder (cfolder_t **cfolder, GInputStream *stream);
+GCabFolder * gcab_folder_new_steal_cfolder (cfolder_t **cfolder);
GCabFile * gcab_file_new_steal_cfile (cfile_t **cfile);
gboolean gcab_file_update_info (GCabFile *file, GFileInfo *info);
@@ -53,6 +53,7 @@ void gcab_file_add_attribute (GCabFile *file, guint32 at
gsize gcab_folder_get_ndatablocks (GCabFolder *folder);
gboolean gcab_folder_extract (GCabFolder *self,
+ GDataInputStream *data,
GFile *path,
guint8 res_data,
GCabFileCallback file_callback,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]