From 8297a178c45e02d85fa69cf8d4339c293b54518e Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Thu, 9 Jul 2020 14:29:27 +0100 Subject: [PATCH] Minor updates to accel_key_to_keys Make "modifiers" static, potentially avoids a copy to stack. Use G_N_ELEMENTS also to allocate keys, as in the next loop allowing to easily change "modifiers" size. Signed-off-by: Frediano Ziglio --- src/virt-viewer-window.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c index 9bf3b44..6c9bc41 100644 --- a/src/virt-viewer-window.c +++ b/src/virt-viewer-window.c @@ -705,7 +705,7 @@ accel_key_to_keys(const GtkAccelKey *key) { guint i; guint *val, *keys; - const struct { + static const struct { const guint mask; const guint key; } modifiers[] = { @@ -717,7 +717,7 @@ accel_key_to_keys(const GtkAccelKey *key) g_warn_if_fail((key->accel_mods & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0); - keys = val = g_new(guint, 5); /* up to 3 modifiers, key and the stop symbol */ + keys = val = g_new(guint, G_N_ELEMENTS(modifiers) + 2); /* up to 3 modifiers, key and the stop symbol */ /* first, send the modifiers */ for (i = 0; i < G_N_ELEMENTS(modifiers); i++) { if (key->accel_mods & modifiers[i].mask)