[glib/nacho/gtask-performance] gtask: use strdup_printf in g_task_return only if needed
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/nacho/gtask-performance] gtask: use strdup_printf in g_task_return only if needed
- Date: Fri, 13 May 2022 15:55:43 +0000 (UTC)
commit 8f91e5c4de3fab8f708f979ede60dca4732f09ef
Author: Ignacio Casal Quinteiro <qignacio amazon com>
Date: Fri May 13 16:43:38 2022 +0200
gtask: use strdup_printf in g_task_return only if needed
If the task name is NULL there is no need to allocate the string
since this can be expensive if called very often
gio/gtask.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/gio/gtask.c b/gio/gtask.c
index 80c0863ff6..4165ba0999 100644
--- a/gio/gtask.c
+++ b/gio/gtask.c
@@ -1257,7 +1257,6 @@ g_task_return (GTask *task,
GTaskReturnType type)
{
GSource *source;
- gchar *source_name = NULL;
if (type != G_TASK_RETURN_FROM_THREAD)
task->ever_returned = TRUE;
@@ -1306,10 +1305,21 @@ g_task_return (GTask *task,
/* Otherwise, complete in the next iteration */
source = g_idle_source_new ();
- source_name = g_strdup_printf ("[gio] %s complete_in_idle_cb",
- (task->name != NULL) ? task->name : "(unnamed)");
- g_source_set_name (source, source_name);
- g_free (source_name);
+
+ /* Note: in case the task name is NULL we set it as a const string instead
+ * of going through the printf path which is expensive and may show in the
+ * profiler if g_task_return is called very often
+ */
+ if (task->name == NULL)
+ g_source_set_name (source, "[gio] (unnamed) complete_in_idle_cb");
+ else
+ {
+ gchar *source_name;
+
+ source_name = g_strdup_printf ("[gio] %s complete_in_idle_cb", task->name);
+ g_free (source_name);
+ }
+
g_task_attach_source (task, source, complete_in_idle_cb);
g_source_unref (source);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]