Use pre-allocated array sizes and packed where possible in intl

This commit is contained in:
Niels Dossche 2025-04-20 02:21:04 +02:00
parent 68b904884b
commit e9b01f202b
4 changed files with 14 additions and 7 deletions

View file

@ -469,7 +469,8 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
ZVAL_COPY_VALUE(&garbage, array); ZVAL_COPY_VALUE(&garbage, array);
/* for resulting hash we'll assign new hash keys rather then reordering */ /* for resulting hash we'll assign new hash keys rather then reordering */
array_init(array); array_init_size(array, sortKeyCount);
zend_hash_real_init_packed(Z_ARRVAL_P(array));
for( j = 0; j < sortKeyCount; j++ ) for( j = 0; j < sortKeyCount; j++ )
{ {

View file

@ -294,7 +294,8 @@ static void php_converter_from_u_callback(const void *context,
zval zargs[4]; zval zargs[4];
ZVAL_LONG(&zargs[0], reason); ZVAL_LONG(&zargs[0], reason);
array_init(&zargs[1]); array_init_size(&zargs[1], length);
zend_hash_real_init_packed(Z_ARRVAL(zargs[1]));
int i = 0; int i = 0;
while (i < length) { while (i < length) {
UChar32 c; UChar32 c;
@ -807,7 +808,8 @@ PHP_METHOD(UConverter, getAvailable) {
intl_error_reset(NULL); intl_error_reset(NULL);
array_init(return_value); array_init_size(return_value, count);
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
for(i = 0; i < count; i++) { for(i = 0; i < count; i++) {
const char *name = ucnv_getAvailableName(i); const char *name = ucnv_getAvailableName(i);
add_next_index_string(return_value, name); add_next_index_string(return_value, name);
@ -833,7 +835,8 @@ PHP_METHOD(UConverter, getAliases) {
RETURN_FALSE; RETURN_FALSE;
} }
array_init(return_value); array_init_size(return_value, count);
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
for(i = 0; i < count; i++) { for(i = 0; i < count; i++) {
const char *alias; const char *alias;
@ -856,8 +859,9 @@ PHP_METHOD(UConverter, getStandards) {
ZEND_PARSE_PARAMETERS_NONE(); ZEND_PARSE_PARAMETERS_NONE();
intl_error_reset(NULL); intl_error_reset(NULL);
array_init(return_value);
count = ucnv_countStandards(); count = ucnv_countStandards();
array_init_size(return_value, count);
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
for(i = 0; i < count; i++) { for(i = 0; i < count; i++) {
UErrorCode error = U_ZERO_ERROR; UErrorCode error = U_ZERO_ERROR;
const char *name = ucnv_getStandard(i, &error); const char *name = ucnv_getStandard(i, &error);

View file

@ -42,7 +42,8 @@ static void msgfmt_do_parse(MessageFormatter_object *mfo, char *source, size_t s
} }
INTL_METHOD_CHECK_STATUS(mfo, "Parsing failed"); INTL_METHOD_CHECK_STATUS(mfo, "Parsing failed");
array_init(return_value); array_init_size(return_value, count);
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
for(i=0;i<count;i++) { for(i=0;i<count;i++) {
add_next_index_zval(return_value, &fargs[i]); add_next_index_zval(return_value, &fargs[i]);
} }

View file

@ -57,7 +57,8 @@ void resourcebundle_extract_value( zval *return_value, ResourceBundle_object *so
case URES_INT_VECTOR: case URES_INT_VECTOR:
vfield = ures_getIntVector( source->child, &ilen, &INTL_DATA_ERROR_CODE(source) ); vfield = ures_getIntVector( source->child, &ilen, &INTL_DATA_ERROR_CODE(source) );
INTL_METHOD_CHECK_STATUS(source, "Failed to retrieve vector value"); INTL_METHOD_CHECK_STATUS(source, "Failed to retrieve vector value");
array_init( return_value ); array_init_size( return_value, ilen );
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
for (i=0; i<ilen; i++) { for (i=0; i<ilen; i++) {
add_next_index_long( return_value, vfield[i] ); add_next_index_long( return_value, vfield[i] );
} }