Skip to content

Commit e9b01f2

Browse files
committed
Use pre-allocated array sizes and packed where possible in intl
1 parent 68b9048 commit e9b01f2

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

ext/intl/collator/collator_sort.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,8 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
469469

470470
ZVAL_COPY_VALUE(&garbage, array);
471471
/* for resulting hash we'll assign new hash keys rather then reordering */
472-
array_init(array);
472+
array_init_size(array, sortKeyCount);
473+
zend_hash_real_init_packed(Z_ARRVAL_P(array));
473474

474475
for( j = 0; j < sortKeyCount; j++ )
475476
{

ext/intl/converter/converter.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ static void php_converter_from_u_callback(const void *context,
294294
zval zargs[4];
295295

296296
ZVAL_LONG(&zargs[0], reason);
297-
array_init(&zargs[1]);
297+
array_init_size(&zargs[1], length);
298+
zend_hash_real_init_packed(Z_ARRVAL(zargs[1]));
298299
int i = 0;
299300
while (i < length) {
300301
UChar32 c;
@@ -807,7 +808,8 @@ PHP_METHOD(UConverter, getAvailable) {
807808

808809
intl_error_reset(NULL);
809810

810-
array_init(return_value);
811+
array_init_size(return_value, count);
812+
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
811813
for(i = 0; i < count; i++) {
812814
const char *name = ucnv_getAvailableName(i);
813815
add_next_index_string(return_value, name);
@@ -833,7 +835,8 @@ PHP_METHOD(UConverter, getAliases) {
833835
RETURN_FALSE;
834836
}
835837

836-
array_init(return_value);
838+
array_init_size(return_value, count);
839+
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
837840
for(i = 0; i < count; i++) {
838841
const char *alias;
839842

@@ -856,8 +859,9 @@ PHP_METHOD(UConverter, getStandards) {
856859
ZEND_PARSE_PARAMETERS_NONE();
857860
intl_error_reset(NULL);
858861

859-
array_init(return_value);
860862
count = ucnv_countStandards();
863+
array_init_size(return_value, count);
864+
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
861865
for(i = 0; i < count; i++) {
862866
UErrorCode error = U_ZERO_ERROR;
863867
const char *name = ucnv_getStandard(i, &error);

ext/intl/msgformat/msgformat_parse.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ static void msgfmt_do_parse(MessageFormatter_object *mfo, char *source, size_t s
4242
}
4343
INTL_METHOD_CHECK_STATUS(mfo, "Parsing failed");
4444

45-
array_init(return_value);
45+
array_init_size(return_value, count);
46+
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
4647
for(i=0;i<count;i++) {
4748
add_next_index_zval(return_value, &fargs[i]);
4849
}

ext/intl/resourcebundle/resourcebundle.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ void resourcebundle_extract_value( zval *return_value, ResourceBundle_object *so
5757
case URES_INT_VECTOR:
5858
vfield = ures_getIntVector( source->child, &ilen, &INTL_DATA_ERROR_CODE(source) );
5959
INTL_METHOD_CHECK_STATUS(source, "Failed to retrieve vector value");
60-
array_init( return_value );
60+
array_init_size( return_value, ilen );
61+
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
6162
for (i=0; i<ilen; i++) {
6263
add_next_index_long( return_value, vfield[i] );
6364
}

0 commit comments

Comments
 (0)