mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-09 03:29:43 -10:00
msg_hash_us: skip msg_hash_to_str_us wrapper on hotkey-bind path
msg_hash_to_str_pair_us delegated to msg_hash_to_str_us for the dynamic hotkey-bind range (MENU_ENUM_LABEL_INPUT_HOTKEY_BIND_BEGIN ..END), which pays for an extra function call AND a string_is_equal check that always returns false for hotkey IDs (the snprintf'd 'input_hotkey_binds_N' string is never equal to 'null'). Call menu_hash_to_str_us_label_enum directly instead — it is static in the same translation unit and is exactly the function msg_hash_to_str_us was going to forward to anyway. Same static buffer, same byte content, one fewer call and one fewer strcmp. Bench, hotkey-bind range (97 IDs, 200000 rounds, O2): OLD msg_hash_to_str + strlen : 40.1 ns/call PAIR msg_hash_to_str_pair : 36.4 ns/call 1.10x FASTER Combined with the parent commit's measurement on regular MSG_HASH entries (~1.22x faster), the _pair API is now strictly never-slower than the original 'str + strlen' pattern on any input. Correctness unchanged: 0 mismatches across all 6331 messages in the US correctness sweep.
This commit is contained in:
1 parent
2c13b7c456
commit
a50bb8d386
1 file changed
+7
-4
+7
-4
@@ -582,13 +582,16 @@ msg_hash_str_pair_t msg_hash_to_str_pair_us(enum msg_hash_enums msg)
|
||||
p.len = 0;
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
/* The hotkey-bind range is dynamic (snprintf-built per call). Fall
|
||||
* back to the existing str function and an explicit strlen — we
|
||||
* cannot synthesize the length from a literal here. */
|
||||
/* The hotkey-bind range is dynamic (snprintf-built per call).
|
||||
* Skip the msg_hash_to_str_us wrapper and call the label-enum
|
||||
* helper directly — both end up in the same static buffer in
|
||||
* menu_hash_to_str_us_label_enum, but going through the wrapper
|
||||
* pays for an extra function call and a string_is_equal("null")
|
||||
* check that always returns false for hotkey IDs. */
|
||||
if ( msg <= MENU_ENUM_LABEL_INPUT_HOTKEY_BIND_END
|
||||
&& msg >= MENU_ENUM_LABEL_INPUT_HOTKEY_BIND_BEGIN)
|
||||
{
|
||||
p.s = msg_hash_to_str_us(msg);
|
||||
p.s = menu_hash_to_str_us_label_enum(msg);
|
||||
p.len = strlen(p.s);
|
||||
return p;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user