[glib/1525-task-result: 2/2] gtask: Compress GTask struct using a bitfield
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/1525-task-result: 2/2] gtask: Compress GTask struct using a bitfield
- Date: Tue, 2 Oct 2018 09:02:38 +0000 (UTC)
commit 290bb0dd1b5169806e7de2a17ad22a3432661d31
Author: Philip Withnall <withnall endlessm com>
Date: Mon Oct 1 21:51:18 2018 +0100
gtask: Compress GTask struct using a bitfield
There are a lot of gbooleans in the private GTask struct, which seems a
bit wasteful. Use a bitfield to compress the struct a bit.
This reduces the size of the struct from 216 bytes to 168 bytes on my
64-bit machine.
One of the fields needs to remain separate, since it’s used from a
TRACE() macro which calls typeof() on it.
Signed-off-by: Philip Withnall <withnall endlessm com>
gio/gtask.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
---
diff --git a/gio/gtask.c b/gio/gtask.c
index a31bd613a..a40bc01b4 100644
--- a/gio/gtask.c
+++ b/gio/gtask.c
@@ -551,20 +551,26 @@ struct _GTask {
gint64 creation_time;
gint priority;
GCancellable *cancellable;
- gboolean check_cancellable;
GAsyncReadyCallback callback;
gpointer callback_data;
- gboolean completed;
GTaskThreadFunc task_func;
GMutex lock;
GCond cond;
- gboolean return_on_cancel;
+
+ /* This can’t be in the bit field because we access it from TRACE(). */
gboolean thread_cancelled;
- gboolean synchronous;
- gboolean thread_complete;
- gboolean blocking_other_task;
+
+ gboolean check_cancellable : 1;
+ gboolean completed : 1;
+ gboolean return_on_cancel : 1;
+ gboolean synchronous : 1;
+ gboolean thread_complete : 1;
+ gboolean blocking_other_task : 1;
+ gboolean had_error : 1;
+ gboolean result_set : 1;
+ gboolean ever_returned : 1;
GError *error;
union {
@@ -573,9 +579,6 @@ struct _GTask {
gboolean boolean;
} result;
GDestroyNotify result_destroy;
- gboolean had_error;
- gboolean result_set;
- gboolean ever_returned;
};
#define G_TASK_IS_THREADED(task) ((task)->task_func != NULL)
@@ -1635,7 +1638,7 @@ g_task_propagate_pointer (GTask *task,
if (g_task_propagate_error (task, error))
return NULL;
- g_return_val_if_fail (task->result_set == TRUE, NULL);
+ g_return_val_if_fail (task->result_set, NULL);
task->result_destroy = NULL;
task->result_set = FALSE;
@@ -1691,7 +1694,7 @@ g_task_propagate_int (GTask *task,
if (g_task_propagate_error (task, error))
return -1;
- g_return_val_if_fail (task->result_set == TRUE, -1);
+ g_return_val_if_fail (task->result_set, -1);
task->result_set = FALSE;
return task->result.size;
@@ -1746,7 +1749,7 @@ g_task_propagate_boolean (GTask *task,
if (g_task_propagate_error (task, error))
return FALSE;
- g_return_val_if_fail (task->result_set == TRUE, FALSE);
+ g_return_val_if_fail (task->result_set, FALSE);
task->result_set = FALSE;
return task->result.boolean;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]