[gtksourceview/wip/better-use-gtask] FileLoader: move some of the instance variables to a TaskData struct
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/better-use-gtask] FileLoader: move some of the instance variables to a TaskData struct
- Date: Sat, 7 May 2016 10:00:15 +0000 (UTC)
commit f23d1bcdf3feaa57e25d8c6e2e26fb50752ff5fb
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat May 7 11:46:16 2016 +0200
FileLoader: move some of the instance variables to a TaskData struct
It's not a good practice to have too many instance variables. So move
the task-related instance variables to a TaskData struct. It's how GTask
is meant to be used. But GtkSourceFileLoader is a bit special, since
there can be at most one task running at a time, otherwise it would
screw up the GtkSourceBuffer content and FileLoader state. So we still
keep the GTask object as an instance variable.
Moving chunk_buffer to the TaskData struct has the nice effect that we
are no longer limited by the maximum size of a GType instance private
data.
gtksourceview/gtksourcefileloader.c | 65 ++++++++++++++++++++++++++--------
1 files changed, 49 insertions(+), 16 deletions(-)
---
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index 78263e5..4631c22 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -99,37 +99,42 @@ struct _GtkSourceFileLoaderPrivate
GFile *location;
- /* The value of the "input-stream" property. */
+ /* The value of the :input-stream property. Do not confuse with the
+ * input_stream field in TaskData.
+ */
GInputStream *input_stream_property;
GSList *candidate_encodings;
- GFileInfo *info;
const GtkSourceEncoding *auto_detected_encoding;
GtkSourceNewlineType auto_detected_newline_type;
GtkSourceCompressionType auto_detected_compression_type;
GTask *task;
+};
+
+typedef struct _TaskData TaskData;
+struct _TaskData
+{
+ /* The two streams cannot be spliced directly, because:
+ * (1) We need to call the progress callback.
+ * (2) Sync methods must be used for the output stream, and async
+ * methods for the input stream.
+ */
+ GInputStream *input_stream;
+ GtkSourceBufferOutputStream *output_stream;
+
+ GFileInfo *info;
- goffset total_bytes_read;
- goffset total_size;
GFileProgressCallback progress_cb;
gpointer progress_cb_data;
GDestroyNotify progress_cb_notify;
- /* Warning: type instances' private data are limited to a total of 64 KiB.
- * See the GType documentation.
- */
- gchar chunk_buffer[READ_CHUNK_SIZE];
- gssize chunk_bytes_read;
+ goffset total_bytes_read;
+ goffset total_size;
- /* The two streams cannot be spliced directly, because
- * (1) we need to call the progress callback
- * (2) sync methods must be used for the output stream, and async
- * methods for the input stream.
- */
- GInputStream *input_stream;
- GtkSourceBufferOutputStream *output_stream;
+ gssize chunk_bytes_read;
+ gchar chunk_buffer[READ_CHUNK_SIZE];
guint guess_content_type_from_content : 1;
guint tried_mount : 1;
@@ -140,6 +145,34 @@ G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceFileLoader, gtk_source_file_loader, G_TYPE_
static void open_file (GtkSourceFileLoader *loader);
static void read_file_chunk (GtkSourceFileLoader *loader);
+static TaskData *
+task_data_new (void)
+{
+ return g_new0 (TaskData, 1);
+}
+
+static void
+task_data_free (gpointer data)
+{
+ TaskData *task_data = data;
+
+ if (task_data == NULL)
+ {
+ return;
+ }
+
+ g_clear_object (&task_data->input_stream);
+ g_clear_object (&task_data->output_stream);
+ g_clear_object (&task_data->info);
+
+ if (loader->priv->progress_cb_notify != NULL)
+ {
+ loader->priv->progress_cb_notify (loader->priv->progress_cb_data);
+ }
+
+ g_free (task_data);
+}
+
static GtkSourceCompressionType
get_compression_type_from_content_type (const gchar *content_type)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]