Skip to content

Commit 21e1e43

Browse files
committed
Merge pull request #104430 from Ivorforce/add-features-iterate-fast
Optimize `TextServerAdvanced::_add_features` by using iteration instead of `.values()` and `.keys()`
2 parents f7dfd64 + bfc1ef4 commit 21e1e43

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

modules/text_server_adv/text_server_adv.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6125,17 +6125,15 @@ Glyph TextServerAdvanced::_shape_single_glyph(ShapedTextDataAdvanced *p_sd, char
61256125
return gl;
61266126
}
61276127

6128-
_FORCE_INLINE_ void TextServerAdvanced::_add_featuers(const Dictionary &p_source, Vector<hb_feature_t> &r_ftrs) {
6129-
Array keys = p_source.keys();
6130-
Array values = p_source.values();
6131-
for (int i = 0; i < keys.size(); i++) {
6132-
int32_t value = values[i];
6128+
_FORCE_INLINE_ void TextServerAdvanced::_add_features(const Dictionary &p_source, Vector<hb_feature_t> &r_ftrs) {
6129+
for (const KeyValue<Variant, Variant> &key_value : p_source) {
6130+
int32_t value = key_value.value;
61336131
if (value >= 0) {
61346132
hb_feature_t feature;
6135-
if (keys[i].is_string()) {
6136-
feature.tag = _name_to_tag(keys[i]);
6133+
if (key_value.key.is_string()) {
6134+
feature.tag = _name_to_tag(key_value.key);
61376135
} else {
6138-
feature.tag = keys[i];
6136+
feature.tag = key_value.key;
61396137
}
61406138
feature.value = value;
61416139
feature.start = 0;
@@ -6297,8 +6295,8 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_star
62976295
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);
62986296

62996297
Vector<hb_feature_t> ftrs;
6300-
_add_featuers(_font_get_opentype_feature_overrides(f), ftrs);
6301-
_add_featuers(p_sd->spans[p_span].features, ftrs);
6298+
_add_features(_font_get_opentype_feature_overrides(f), ftrs);
6299+
_add_features(p_sd->spans[p_span].features, ftrs);
63026300

63036301
hb_shape(hb_font, p_sd->hb_buffer, ftrs.is_empty() ? nullptr : &ftrs[0], ftrs.size());
63046302

modules/text_server_adv/text_server_adv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ class TextServerAdvanced : public TextServerExtension {
685685
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);
686686
_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);
687687

688-
_FORCE_INLINE_ void _add_featuers(const Dictionary &p_source, Vector<hb_feature_t> &r_ftrs);
688+
_FORCE_INLINE_ void _add_features(const Dictionary &p_source, Vector<hb_feature_t> &r_ftrs);
689689

690690
Mutex ft_mutex;
691691

0 commit comments

Comments
 (0)