From fbec3a728f9505267f04d68b5c7e267f562665b0 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sun, 16 May 2021 15:47:16 +0200 Subject: [PATCH] wmaker: Do not allocate memory for a temporary string for the Window Shortcut menu When creating the list of possible shortcut for windows to populate the window menu, a temporary buffer was allocated to hold that string. As this allocation participates to memory fragmentation, this patch makes use of storage on the stack instead which is also faster. Took opportunity to include the shortcut number (%i) in the string to be translated, because it is unlikely that adding that number at the end of the string is right in all languages. Updated french translation because it is the only one I am confident with. Signed-off-by: Christophe CURIS --- po/fr.po | 4 ++-- src/winmenu.c | 9 ++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/po/fr.po b/po/fr.po index 0f72f2ee..4d6fc597 100644 --- a/po/fr.po +++ b/po/fr.po @@ -1522,8 +1522,8 @@ msgstr "" "Confirmez-vous ?" #: ../src/winmenu.c:274 ../src/winmenu.c:283 -msgid "Set Shortcut" -msgstr "Attribuer le raccourci" +msgid "Set Shortcut %i" +msgstr "Attribuer le raccourci n°%i" #: ../src/winmenu.c:361 ../src/winmenu.c:406 msgid "could not create submenu for window menu" diff --git a/src/winmenu.c b/src/winmenu.c index af7fe627..df5e43ba 100644 --- a/src/winmenu.c +++ b/src/winmenu.c @@ -399,22 +399,18 @@ static void updateMakeShortcutMenu(WMenu * menu, WWindow * wwin) { WMenu *smenu = menu->cascades[menu->entries[MC_OPTIONS]->cascade]; int i; - char *buffer; - int buflen; + char buffer[64]; KeyCode kcode; if (!smenu) return; - buflen = strlen(_("Set Shortcut")) + 16; - buffer = wmalloc(buflen); - for (i = wlengthof(menu_options_entries); i < smenu->entry_no; i++) { int shortcutNo = i - wlengthof(menu_options_entries); WMenuEntry *entry = smenu->entries[i]; WMArray *shortSelWindows = wwin->screen_ptr->shortcutWindows[shortcutNo]; - snprintf(buffer, buflen, "%s %i", _("Set Shortcut"), shortcutNo + 1); + snprintf(buffer, sizeof(buffer), _("Set Shortcut %i"), shortcutNo + 1); if (!shortSelWindows) { entry->flags.indicator_on = 0; @@ -469,7 +465,6 @@ static void updateMakeShortcutMenu(WMenu * menu, WWindow * wwin) } entry->clientdata = wwin; } - wfree(buffer); if (!smenu->flags.realized) wMenuRealize(smenu); }