Skip to content

Commit 14c4d2e

Browse files
committed
ext/intl: refactor to use array_init_size instead of array_init when the size is known
1 parent 51911cc commit 14c4d2e

4 files changed

Lines changed: 5 additions & 5 deletions

File tree

ext/intl/calendar/calendar_class.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static HashTable *Calendar_get_debug_info(zend_object *object, int *is_temp)
165165
debug_info_tz = Z_OBJ_HANDLER(ztz, get_debug_info)(Z_OBJ(ztz), &is_tmp);
166166
assert(is_tmp == 1);
167167

168-
array_init(&ztz_debug);
168+
array_init_size(&ztz_debug, zend_hash_num_elements(debug_info_tz));
169169
zend_hash_copy(Z_ARRVAL(ztz_debug), debug_info_tz, zval_add_ref);
170170
zend_hash_destroy(debug_info_tz);
171171
FREE_HASHTABLE(debug_info_tz);

ext/intl/calendar/calendar_methods.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_available_locales)
203203

204204
int32_t count;
205205
const Locale *availLocales = Calendar::getAvailableLocales(count);
206-
array_init(return_value);
206+
array_init_size(return_value, count);
207207
for (int i = 0; i < count; i++) {
208208
Locale locale = availLocales[i];
209209
add_next_index_string(return_value, locale.getName());

ext/intl/dateformat/dateformat_parse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* tex
108108
INTL_METHOD_CHECK_STATUS( dfo, "Date parsing failed" );
109109

110110

111-
array_init( return_value );
111+
array_init_size( return_value, 9 );
112112
/* Add entries from various fields of the obtained parsed_calendar */
113113
add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_SECOND, CALENDAR_SEC);
114114
add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_MINUTE, CALENDAR_MIN);

ext/intl/uchar/uchar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ IC_METHOD(charAge) {
493493
}
494494

495495
u_charAge(cp, version);
496-
array_init(return_value);
496+
array_init_size(return_value, U_MAX_VERSION_LENGTH);
497497
for(i = 0; i < U_MAX_VERSION_LENGTH; ++i) {
498498
add_next_index_long(return_value, version[i]);
499499
}
@@ -508,7 +508,7 @@ IC_METHOD(getUnicodeVersion) {
508508
ZEND_PARSE_PARAMETERS_NONE();
509509

510510
u_getUnicodeVersion(version);
511-
array_init(return_value);
511+
array_init_size(return_value, U_MAX_VERSION_LENGTH);
512512
for(i = 0; i < U_MAX_VERSION_LENGTH; ++i) {
513513
add_next_index_long(return_value, version[i]);
514514
}

0 commit comments

Comments
 (0)