mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-07 08:36:02 -10:00
msg_hash: drop the dead "null" sentinel compare in msg_hash_to_str()
msg_hash_to_str() looked up the active language's packed string table
and then re-checked the result against the literal untranslated
marker:
if (ret && strcmp(ret, "null") != 0)
return ret;
return msg_hash_to_str_us(msg);
No row reachable through that lookup can hold "null". intl/json2h.py
drops such rows when it packs a table, on the grounds that a missing
row and a "null" row both mean "fall back to the base table" and are
indistinguishable to msg_hash_strtab_lookup(). The compare is
therefore checking for something the data cannot contain.
Verified against the committed tables rather than the generator's
claim: probing all 36 language strtabs across every enum id, 231,228
(language x id) pairs, found 102,777 rows present and zero equal to
"null".
The compare is not only dead but semantically wrong: "null" is the
ordinary German, Dutch, Danish and Norwegian word for zero, so a
legitimate translation whose value happened to be "null" would have
been discarded and silently replaced with English. Removing the
compare is a prerequisite for ever fixing that at the generator end;
leaving it in would keep the conflation alive at runtime.
Cost, measured against a faithful copy of the previous body linked
into the same binary, best of 5 at -O2 over the translated-row path:
German 11.96 ns -> 6.98 ns (-4.98 ns, 42%)
French 11.78 ns -> 6.66 ns (-5.11 ns, 43%)
Japanese 11.44 ns -> 6.67 ns (-4.77 ns, 42%)
English is unaffected either way: no English strtab exists, so ret is
always NULL and the compare was short-circuited. A 20 s ozone
session issues roughly 50.7M msg_hash_to_str() calls, about 20.3M of
which reach a translated row, so this was a cost borne only by
non-English users.
Equivalence checked exhaustively: the previous and current bodies
return identical strings for all 237,651 (language x id) pairs across
every RETRO_LANGUAGE value, zero differences.
Note that the similar check in msg_hash_to_str_us() must stay:
menu_hash_to_str_us_label_enum() really does return the literal
"null" as its not-found sentinel, so that one is live.
This commit is contained in:
1 parent
7c0ca1646a
commit
580e787775
1 file changed
+8
-1
+8
-1
@@ -532,7 +532,14 @@ const char *msg_hash_to_str(enum msg_hash_enums msg)
|
||||
&msg_hash_lang_index, (uint32_t)msg);
|
||||
}
|
||||
#endif
|
||||
if (ret && strcmp(ret, "null") != 0)
|
||||
/* No strtab row can hold the untranslated marker: json2h.py drops
|
||||
* "null" rows at pack time, since a missing row and a "null" row both
|
||||
* mean "fall back to the base table" and are indistinguishable at
|
||||
* lookup. Verified exhaustively over all 36 language tables x every
|
||||
* enum id. So a non-NULL ret is always a real translation, and the
|
||||
* strcmp that used to guard this return was dead weight paid on
|
||||
* roughly 40 percent of calls for every non-English user. */
|
||||
if (ret)
|
||||
return ret;
|
||||
return msg_hash_to_str_us(msg);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user