1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

enchant: Use an array of the correct size before filling it (#20743)

This avoids the need to do resizes.
This commit is contained in:
Niels Dossche
2025-12-20 15:59:07 -08:00
committed by GitHub
parent 3e87cfa9c8
commit 5dd5a4267f

View File

@@ -671,17 +671,18 @@ PHP_FUNCTION(enchant_dict_suggest)
}
PHP_ENCHANT_GET_DICT;
array_init(return_value);
suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg);
if (suggs && n_sugg) {
size_t i;
array_init_size(return_value, n_sugg);
for (i = 0; i < n_sugg; i++) {
for (size_t i = 0; i < n_sugg; i++) {
add_next_index_string(return_value, suggs[i]);
}
enchant_dict_free_string_list(pdict->pdict, suggs);
} else {
RETURN_EMPTY_ARRAY();
}
}
/* }}} */