menu/drivers: deduplicate menu_state_get_ptr() calls

menu_state_get_ptr() is a trivial getter that returns &menu_driver_state
(file-scope static).  It cannot be inlined across TUs without LTO, so
every call is a real function call returning a constant pointer.  Four
menu drivers had accumulated redundant calls that can be folded into
the existing function-top menu_st caches without any behavioural change.

Two patterns addressed:

1. Inner-block shadows -- a function caches menu_st at the top, then a
   nested block re-declares its own menu_st = menu_state_get_ptr().
   Since the outer cache is in scope and menu_st is never reassigned
   anywhere in these files, the inner shadow always binds the same
   pointer.  Drop the inner declaration and let the block use the
   outer one.

2. Direct chained calls -- menu_state_get_ptr()->field used in a
   function that already has menu_st cached.  Replace with menu_st->field.

   Plus one site (rgui_populate_entries) where three direct calls
   coexist with no cache; add a function-top cache and replace the
   three calls with menu_st-> accesses.

Per-function changes:

  materialui.c:
    materialui_frame                     -1 (inner shadow)
    materialui_populate_entries          -6 (1 inner shadow + 5 direct)
    materialui_parse_menu_entry_action   -6 (6 inner shadows in switch arms)
    materialui_pointer_up                -1 (inner shadow)

  xmb.c:
    xmb_parse_menu_entry_action          -1 (inner shadow)
    xmb_render                           -2 (2 inner shadows in drag arms)

  rgui.c:
    rgui_render                          -1 (inner shadow)
    rgui_populate_entries                -2 net (3 direct -> cache, +1 cache)
    rgui_pointer_up                      -1 (inner shadow)

  ozone.c:
    ozone_parse_menu_entry_action        -1 (inner shadow)
    ozone_frame                          -1 (inner shadow)

Total: 23 fewer calls (122 -> 99 across the four files), -16 source
lines net.  No semantic change -- menu_state_get_ptr() returns the
same pointer every time, and no caller reassigns the cached menu_st
anywhere in the touched files (verified by grep).
This commit is contained in:
U-DESKTOP-SPFP6AQ\twistedtechre committed 2026-05-01 03:18:39 +02:00
1 parent 02f6844705
commit 40ad5bc920
4 files changed
+9 -25

No files matched your search

+5 -14
View File
@@ -8084,7 +8084,6 @@ static void materialui_frame(void *data, video_frame_info_t *video_info)
{
size_t _len;
char msg[NAME_MAX_LENGTH];
struct menu_state *menu_st = menu_state_get_ptr();
const char *str = menu_input_dialog_get_buffer();
const char *label = menu_st->input_dialog_kb_label;
@@ -9812,7 +9811,6 @@ static void materialui_populate_entries(void *data, const char *path,
mui->playlist = NULL;
if (mui->flags & MUI_FLAG_IS_PLAYLIST)
{
struct menu_state *menu_st = menu_state_get_ptr();
menu_list_t *menu_list = menu_st->entries.list;
file_list_t *list = menu_list ? MENU_LIST_GET_SELECTION(menu_list, 0) : NULL;
size_t list_size = list ? list->size : 0;
@@ -9856,25 +9854,25 @@ static void materialui_populate_entries(void *data, const char *path,
if ( (remember_selection == MENU_REMEMBER_SELECTION_ALWAYS
|| remember_selection == MENU_REMEMBER_SELECTION_PLAYLISTS)
&& mui->playlist_selection_ptr < MUI_PLAYLIST_SELECTION_MAX)
menu_state_get_ptr()->selection_ptr = mui->playlist_selection[mui->playlist_selection_ptr];
menu_st->selection_ptr = mui->playlist_selection[mui->playlist_selection_ptr];
}
else if (mui->flags & MUI_FLAG_IS_PLAYLISTS_TAB)
{
if ( remember_selection == MENU_REMEMBER_SELECTION_ALWAYS
|| remember_selection == MENU_REMEMBER_SELECTION_PLAYLISTS)
menu_state_get_ptr()->selection_ptr = mui->playlist_selection_ptr;
menu_st->selection_ptr = mui->playlist_selection_ptr;
}
else if (string_is_equal(mui->menu_title, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_MAIN_MENU)))
{
if ( remember_selection == MENU_REMEMBER_SELECTION_ALWAYS
|| remember_selection == MENU_REMEMBER_SELECTION_MAIN)
menu_state_get_ptr()->selection_ptr = mui->mainmenu_selection_ptr;
menu_st->selection_ptr = mui->mainmenu_selection_ptr;
}
else if (string_is_equal(mui->menu_title, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SETTINGS)))
{
if ( remember_selection == MENU_REMEMBER_SELECTION_ALWAYS
|| remember_selection == MENU_REMEMBER_SELECTION_MAIN)
menu_state_get_ptr()->selection_ptr = mui->settings_selection_ptr;
menu_st->selection_ptr = mui->settings_selection_ptr;
}
if ( settings->bools.savestate_thumbnail_enable
@@ -9883,7 +9881,7 @@ static void materialui_populate_entries(void *data, const char *path,
{
mui->flags |= MUI_FLAG_IS_SAVESTATE_LIST;
materialui_update_savestate_thumbnail_path(mui,
(unsigned)menu_state_get_ptr()->selection_ptr);
(unsigned)menu_st->selection_ptr);
materialui_update_savestate_thumbnail_image(mui);
}
else
@@ -10366,7 +10364,6 @@ static enum menu_action materialui_parse_menu_entry_action(
materialui_auto_select_onscreen_entry(mui, MUI_ONSCREEN_ENTRY_CENTRE);
else
{
struct menu_state *menu_st = menu_state_get_ptr();
size_t selection = menu_st->selection_ptr;
/* In all other cases, if current selection is off
@@ -10417,12 +10414,10 @@ static enum menu_action materialui_parse_menu_entry_action(
* 'scan' action *if* current selection is
* on screen */
{
struct menu_state *menu_st = menu_state_get_ptr();
size_t selection = menu_st->selection_ptr;
if (mui->flags & MUI_FLAG_IS_PLAYLISTS_TAB)
{
struct menu_state *menu_st = menu_state_get_ptr();
size_t selection_total = menu_st->entries.list ? MENU_LIST_GET_SELECTION(menu_st->entries.list, 0)->size : 0;
size_t selection = menu_st->selection_ptr;
size_t new_selection = random_range(0, (unsigned)(selection_total - 1));
@@ -10496,7 +10491,6 @@ static enum menu_action materialui_parse_menu_entry_action(
* 'start' action *if* current selection is
* on screen */
{
struct menu_state *menu_st = menu_state_get_ptr();
size_t selection = menu_st->selection_ptr;
if ( (mui->flags & MUI_FLAG_IS_PLAYLIST)
@@ -10545,7 +10539,6 @@ static enum menu_action materialui_parse_menu_entry_action(
* In addition, an 'info' action is only valid in general
* if the currently selected entry is on screen */
{
struct menu_state *menu_st = menu_state_get_ptr();
size_t selection = menu_st->selection_ptr;
/* - If this is a playlist, 'info' command is used
@@ -10574,7 +10567,6 @@ static enum menu_action materialui_parse_menu_entry_action(
* selected item is on screen. If it
* is off screen, must disable input */
{
struct menu_state *menu_st = menu_state_get_ptr();
size_t selection = menu_st->selection_ptr;
if (!materialui_entry_onscreen(mui, selection))
@@ -11123,7 +11115,6 @@ static int materialui_pointer_up(void *userdata,
{
int entry_x;
int entry_y;
struct menu_state *menu_st = menu_state_get_ptr();
menu_list_t *menu_list = menu_st->entries.list;
file_list_t *list = NULL;
materialui_node_t *node = NULL;
-2
View File
@@ -8608,7 +8608,6 @@ static enum menu_action ozone_parse_menu_entry_action(
}
else if (ozone->flags2 & OZONE_FLAG2_IS_PLAYLISTS_TAB)
{
struct menu_state *menu_st = menu_state_get_ptr();
size_t selection_total = menu_st->entries.list ? MENU_LIST_GET_SELECTION(menu_st->entries.list, 0)->size : 0;
size_t selection = menu_st->selection_ptr;
size_t new_selection = random_range(0, (unsigned)(selection_total - 1));
@@ -12339,7 +12338,6 @@ static void ozone_frame(void *data, video_frame_info_t *video_info)
if (draw_osk)
{
struct menu_state *menu_st = menu_state_get_ptr();
const char *label = menu_st->input_dialog_kb_label;
const char *str = menu_input_dialog_get_buffer();
+4 -6
View File
@@ -5312,7 +5312,6 @@ static void rgui_render(void *data, unsigned width, unsigned height,
char thumbnail_title_buf[NAME_MAX_LENGTH];
unsigned title_x, title_width;
const char *thumbnail_title = NULL;
struct menu_state *menu_st = menu_state_get_ptr();
bool is_state_slot = *rgui->savestate_thumbnail_file_path;
thumbnail_title_buf[0] = '\0';
@@ -7444,6 +7443,7 @@ static void rgui_populate_entries(
{
rgui_t *rgui = (rgui_t*)data;
settings_t *settings = config_get_ptr();
struct menu_state *menu_st = menu_state_get_ptr();
#if defined(DINGUX)
unsigned aspect_ratio_lock = RGUI_ASPECT_RATIO_LOCK_NONE;
#else
@@ -7551,19 +7551,19 @@ static void rgui_populate_entries(
{
if ( remember_selection == MENU_REMEMBER_SELECTION_ALWAYS
|| remember_selection == MENU_REMEMBER_SELECTION_PLAYLISTS)
menu_state_get_ptr()->selection_ptr = rgui->playlist_selection[rgui->playlist_selection_ptr];
menu_st->selection_ptr = rgui->playlist_selection[rgui->playlist_selection_ptr];
}
else if (rgui->flags & RGUI_FLAG_IS_PLAYLISTS_TAB)
{
if ( remember_selection == MENU_REMEMBER_SELECTION_ALWAYS
|| remember_selection == MENU_REMEMBER_SELECTION_PLAYLISTS)
menu_state_get_ptr()->selection_ptr = rgui->playlist_selection_ptr;
menu_st->selection_ptr = rgui->playlist_selection_ptr;
}
else if (string_is_equal(label, MENU_ENUM_LABEL_SETTINGS_STR))
{
if ( remember_selection == MENU_REMEMBER_SELECTION_ALWAYS
|| remember_selection == MENU_REMEMBER_SELECTION_MAIN)
menu_state_get_ptr()->selection_ptr = rgui->settings_selection_ptr;
menu_st->selection_ptr = rgui->settings_selection_ptr;
}
rgui_navigation_set(data, true);
@@ -7694,8 +7694,6 @@ static int rgui_pointer_up(
return rgui_menu_entry_action(rgui, entry, selection, MENU_ACTION_CANCEL);
else if (ptr <= (end - 1))
{
struct menu_state *menu_st = menu_state_get_ptr();
/* Perform 'select' on the pointed item */
menu_st->selection_ptr = ptr;
rgui_navigation_set(rgui, false);
-3
View File
@@ -6118,7 +6118,6 @@ static enum menu_action xmb_parse_menu_entry_action(
case MENU_ACTION_SCAN:
if (xmb->is_playlist_tab)
{
struct menu_state *menu_st = menu_state_get_ptr();
size_t selection_total = menu_st->entries.list ? MENU_LIST_GET_SELECTION(menu_st->entries.list, 0)->size : 0;
size_t selection = menu_st->selection_ptr;
size_t new_selection = random_range(0, (unsigned)(selection_total - 1));
@@ -7148,7 +7147,6 @@ static void xmb_render(void *data,
/* If category changed, do full switch */
if (nearest != xmb->categories_selection_ptr)
{
struct menu_state *menu_st = menu_state_get_ptr();
menu_list_t *menu_list = menu_st->entries.list;
file_list_t *selection_buf = MENU_LIST_GET_SELECTION(menu_list, 0);
@@ -7173,7 +7171,6 @@ static void xmb_render(void *data,
else if (xmb->drag_mode == XMB_DRAG_VERTICAL)
{
/* Apply vertical drag to list selection */
struct menu_state *menu_st = menu_state_get_ptr();
menu_list_t *menu_list = menu_st->entries.list;
size_t list_size = MENU_LIST_GET_SELECTION(menu_list, 0)->size;