[glib/th/gsignal-cleanup: 1/3] gsignal: use stack allocate temporary buffer in g_signal_new_valist()
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/th/gsignal-cleanup: 1/3] gsignal: use stack allocate temporary buffer in g_signal_new_valist()
- Date: Tue, 26 Jan 2021 13:44:49 +0000 (UTC)
commit 048a24ca7aa2024d4d01646720a6b0f0e263de96
Author: Thomas Haller <thaller redhat com>
Date: Tue Jan 26 13:38:18 2021 +0100
gsignal: use stack allocate temporary buffer in g_signal_new_valist()
g_signal_new_valist() is called by g_signal_new(), which is probably
the most common way to create a signal.
Also, in almost all cases is the number of signal parameters small.
Let's optimize for that by using a stack allocated buffer if we have
few parameters.
gobject/gsignal.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
---
diff --git a/gobject/gsignal.c b/gobject/gsignal.c
index 4e50a2be2..eb69edf61 100644
--- a/gobject/gsignal.c
+++ b/gobject/gsignal.c
@@ -1952,30 +1952,35 @@ g_signal_new_valist (const gchar *signal_name,
GSignalFlags signal_flags,
GClosure *class_closure,
GSignalAccumulator accumulator,
- gpointer accu_data,
+ gpointer accu_data,
GSignalCMarshaller c_marshaller,
GType return_type,
guint n_params,
va_list args)
{
+ GType param_types_stack[200 / sizeof (GType)];
+ GType *param_types_heap = NULL;
GType *param_types;
guint i;
guint signal_id;
+ param_types = param_types_stack;
if (n_params > 0)
{
- param_types = g_new (GType, n_params);
+ if (G_UNLIKELY (n_params > G_N_ELEMENTS(param_types_stack)))
+ {
+ param_types_heap = g_new (GType, n_params);
+ param_types = param_types_heap;
+ }
for (i = 0; i < n_params; i++)
- param_types[i] = va_arg (args, GType);
+ param_types[i] = va_arg (args, GType);
}
- else
- param_types = NULL;
signal_id = g_signal_newv (signal_name, itype, signal_flags,
- class_closure, accumulator, accu_data, c_marshaller,
- return_type, n_params, param_types);
- g_free (param_types);
+ class_closure, accumulator, accu_data, c_marshaller,
+ return_type, n_params, param_types);
+ g_free (param_types_heap);
return signal_id;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]