1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-13 13:31:48 +00:00

Merge pull request #104430 from Ivorforce/add-features-iterate-fast

Optimize `TextServerAdvanced::_add_features` by using iteration instead of `.values()` and `.keys()`
This commit is contained in:
Rémi Verschelde
2025-03-21 13:04:19 +01:00
2 changed files with 9 additions and 11 deletions

View File

@@ -6125,17 +6125,15 @@ Glyph TextServerAdvanced::_shape_single_glyph(ShapedTextDataAdvanced *p_sd, char
return gl; return gl;
} }
_FORCE_INLINE_ void TextServerAdvanced::_add_featuers(const Dictionary &p_source, Vector<hb_feature_t> &r_ftrs) { _FORCE_INLINE_ void TextServerAdvanced::_add_features(const Dictionary &p_source, Vector<hb_feature_t> &r_ftrs) {
Array keys = p_source.keys(); for (const KeyValue<Variant, Variant> &key_value : p_source) {
Array values = p_source.values(); int32_t value = key_value.value;
for (int i = 0; i < keys.size(); i++) {
int32_t value = values[i];
if (value >= 0) { if (value >= 0) {
hb_feature_t feature; hb_feature_t feature;
if (keys[i].is_string()) { if (key_value.key.is_string()) {
feature.tag = _name_to_tag(keys[i]); feature.tag = _name_to_tag(key_value.key);
} else { } else {
feature.tag = keys[i]; feature.tag = key_value.key;
} }
feature.value = value; feature.value = value;
feature.start = 0; feature.start = 0;
@@ -6297,8 +6295,8 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_star
hb_buffer_add_utf32(p_sd->hb_buffer, (const uint32_t *)p_sd->text.ptr(), p_sd->text.length(), p_start, p_end - p_start); hb_buffer_add_utf32(p_sd->hb_buffer, (const uint32_t *)p_sd->text.ptr(), p_sd->text.length(), p_start, p_end - p_start);
Vector<hb_feature_t> ftrs; Vector<hb_feature_t> ftrs;
_add_featuers(_font_get_opentype_feature_overrides(f), ftrs); _add_features(_font_get_opentype_feature_overrides(f), ftrs);
_add_featuers(p_sd->spans[p_span].features, ftrs); _add_features(p_sd->spans[p_span].features, ftrs);
hb_shape(hb_font, p_sd->hb_buffer, ftrs.is_empty() ? nullptr : &ftrs[0], ftrs.size()); hb_shape(hb_font, p_sd->hb_buffer, ftrs.is_empty() ? nullptr : &ftrs[0], ftrs.size());

View File

@@ -685,7 +685,7 @@ class TextServerAdvanced : public TextServerExtension {
Glyph _shape_single_glyph(ShapedTextDataAdvanced *p_sd, char32_t p_char, hb_script_t p_script, hb_direction_t p_direction, const RID &p_font, int64_t p_font_size); Glyph _shape_single_glyph(ShapedTextDataAdvanced *p_sd, char32_t p_char, hb_script_t p_script, hb_direction_t p_direction, const RID &p_font, int64_t p_font_size);
_FORCE_INLINE_ RID _find_sys_font_for_text(const RID &p_fdef, const String &p_script_code, const String &p_language, const String &p_text); _FORCE_INLINE_ RID _find_sys_font_for_text(const RID &p_fdef, const String &p_script_code, const String &p_language, const String &p_text);
_FORCE_INLINE_ void _add_featuers(const Dictionary &p_source, Vector<hb_feature_t> &r_ftrs); _FORCE_INLINE_ void _add_features(const Dictionary &p_source, Vector<hb_feature_t> &r_ftrs);
Mutex ft_mutex; Mutex ft_mutex;