diff options
Diffstat (limited to 'core/string')
-rw-r--r-- | core/string/string_name.h | 12 | ||||
-rw-r--r-- | core/string/translation.cpp | 1 |
2 files changed, 13 insertions, 0 deletions
diff --git a/core/string/string_name.h b/core/string/string_name.h index 9653d2b4cf..f767f3e1ec 100644 --- a/core/string/string_name.h +++ b/core/string/string_name.h @@ -181,6 +181,18 @@ bool operator!=(const char *p_name, const StringName &p_string_name); StringName _scs_create(const char *p_chr, bool p_static = false); +/* + * The SNAME macro is used to speed up StringName creation, as it allows caching it after the first usage in a very efficient way. + * It should NOT be used everywhere, but instead in places where high performance is required and the creation of a StringName + * can be costly. Places where it should be used are: + * - Control::get_theme_*(<name> and Window::get_theme_*(<name> functions. + * - emit_signal(<name>,..) function + * - call_deferred(<name>,..) function + * - Comparisons to a StringName in overriden _set and _get methods. + * + * Use in places that can be called hundreds of times per frame (or more) is recommended, but this situation is very rare. If in doubt, do not use. + */ + #define SNAME(m_arg) ([]() -> const StringName & { static StringName sname = _scs_create(m_arg, true); return sname; })() #endif // STRING_NAME_H diff --git a/core/string/translation.cpp b/core/string/translation.cpp index 7cc41df9ef..eeac8b0acf 100644 --- a/core/string/translation.cpp +++ b/core/string/translation.cpp @@ -925,6 +925,7 @@ bool TranslationServer::is_placeholder(String &p_message, int p_index) const { void TranslationServer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_locale", "locale"), &TranslationServer::set_locale); ClassDB::bind_method(D_METHOD("get_locale"), &TranslationServer::get_locale); + ClassDB::bind_method(D_METHOD("get_tool_locale"), &TranslationServer::get_tool_locale); ClassDB::bind_method(D_METHOD("compare_locales", "locale_a", "locale_b"), &TranslationServer::compare_locales); ClassDB::bind_method(D_METHOD("standardize_locale", "locale"), &TranslationServer::standardize_locale); |