Skip to content

Commit 5dd5a42

Browse files
authored
enchant: Use an array of the correct size before filling it (#20743)
This avoids the need to do resizes.
1 parent 3e87cfa commit 5dd5a42

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

ext/enchant/enchant.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,17 +671,18 @@ PHP_FUNCTION(enchant_dict_suggest)
671671
}
672672

673673
PHP_ENCHANT_GET_DICT;
674-
array_init(return_value);
675674

676675
suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg);
677676
if (suggs && n_sugg) {
678-
size_t i;
677+
array_init_size(return_value, n_sugg);
679678

680-
for (i = 0; i < n_sugg; i++) {
679+
for (size_t i = 0; i < n_sugg; i++) {
681680
add_next_index_string(return_value, suggs[i]);
682681
}
683682

684683
enchant_dict_free_string_list(pdict->pdict, suggs);
684+
} else {
685+
RETURN_EMPTY_ARRAY();
685686
}
686687
}
687688
/* }}} */

0 commit comments

Comments
 (0)