Commit 5dd5a4267f8 for php.net
commit 5dd5a4267f84971025bf8b316fd11910b4a1e03e
Author: Niels Dossche <7771979+ndossche@users.noreply.github.com>
Date: Sat Dec 20 15:59:07 2025 -0800
enchant: Use an array of the correct size before filling it (#20743)
This avoids the need to do resizes.
diff --git a/ext/enchant/enchant.c b/ext/enchant/enchant.c
index eedb49b69e8..534908f9d1c 100644
--- a/ext/enchant/enchant.c
+++ b/ext/enchant/enchant.c
@@ -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();
}
}
/* }}} */