Merge branch 'nacho/gtask-performance' into 'main'

gtask: use g_strconcat() in g_task_return() only if needed

See merge request GNOME/glib!2654
This commit is contained in:
Philip Withnall 2022-05-16 12:52:01 +00:00
commit 6ad8205949

View File

@ -1257,7 +1257,6 @@ g_task_return (GTask *task,
GTaskReturnType type) GTaskReturnType type)
{ {
GSource *source; GSource *source;
gchar *source_name = NULL;
if (type != G_TASK_RETURN_FROM_THREAD) if (type != G_TASK_RETURN_FROM_THREAD)
task->ever_returned = TRUE; task->ever_returned = TRUE;
@ -1306,10 +1305,22 @@ g_task_return (GTask *task,
/* Otherwise, complete in the next iteration */ /* Otherwise, complete in the next iteration */
source = g_idle_source_new (); source = g_idle_source_new ();
source_name = g_strdup_printf ("[gio] %s complete_in_idle_cb",
(task->name != NULL) ? task->name : "(unnamed)"); /* Note: in case the task name is NULL we set it as a const string instead
g_source_set_name (source, source_name); * of going through the concat path which is more expensive and may show in the
g_free (source_name); * profiler if g_task_return is called very often
*/
if (task->name == NULL)
g_source_set_static_name (source, "[gio] (unnamed) complete_in_idle_cb");
else
{
gchar *source_name;
source_name = g_strconcat ("[gio] ", task->name, " complete_in_idle_cb", NULL);
g_source_set_name (source, source_name);
g_free (source_name);
}
g_task_attach_source (task, source, complete_in_idle_cb); g_task_attach_source (task, source, complete_in_idle_cb);
g_source_unref (source); g_source_unref (source);
} }