1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-18 20:10:29 +01:00

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 <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS
2021-05-16 15:47:16 +02:00
committed by Carlos R. Mafra
parent 944bb49997
commit fbec3a728f
2 changed files with 4 additions and 9 deletions

View File

@@ -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"

View File

@@ -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);
}