Skip to content

Commit 900797e

Browse files
authored
ext/intl: various optimization (#22069)
- use array_init_size for known-size arrays - reuse known string lengths
1 parent 6cc51fe commit 900797e

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

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/locale/locale_methods.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ static zend_string* get_icu_value_internal( const char* loc_name , const char* t
457457
efree( mod_loc_name);
458458
}
459459

460-
tag_value->len = strlen(tag_value->val);
460+
tag_value->len = buflen;
461461
return tag_value;
462462
}
463463
/* }}} */
@@ -736,7 +736,7 @@ U_CFUNC PHP_FUNCTION( locale_get_keywords )
736736
Z_PARAM_PATH(loc_name, loc_name_len)
737737
ZEND_PARSE_PARAMETERS_END();
738738

739-
INTL_CHECK_LOCALE_LEN(strlen(loc_name));
739+
INTL_CHECK_LOCALE_LEN(loc_name_len);
740740

741741
if(loc_name_len == 0) {
742742
loc_name = (char *)intl_locale_get_default();
@@ -1127,7 +1127,7 @@ U_CFUNC PHP_FUNCTION(locale_parse)
11271127
Z_PARAM_PATH(loc_name, loc_name_len)
11281128
ZEND_PARSE_PARAMETERS_END();
11291129

1130-
INTL_CHECK_LOCALE_LEN(strlen(loc_name));
1130+
INTL_CHECK_LOCALE_LEN(loc_name_len);
11311131

11321132
if(loc_name_len == 0) {
11331133
loc_name = (char *)intl_locale_get_default();
@@ -1318,7 +1318,7 @@ U_CFUNC PHP_FUNCTION(locale_filter_matches)
13181318

13191319
if( token && (token==cur_lang_tag) ){
13201320
/* check if the char. after match is SEPARATOR */
1321-
chrcheck = token + (strlen(cur_loc_range));
1321+
chrcheck = token + can_loc_range->len;
13221322
if( isIDSeparator(*chrcheck) || isKeywordSeparator(*chrcheck) || isEndOfTag(*chrcheck) ){
13231323
efree( cur_lang_tag );
13241324
efree( cur_loc_range );
@@ -1350,14 +1350,14 @@ U_CFUNC PHP_FUNCTION(locale_filter_matches)
13501350
} /* end of if isCanonical */
13511351
else{
13521352
/* Convert to lower case for case-insensitive comparison */
1353-
cur_lang_tag = reinterpret_cast<char *>(ecalloc( 1, strlen(lang_tag ) + 1));
1353+
cur_lang_tag = reinterpret_cast<char *>(ecalloc(1, lang_tag_len + 1));
13541354

13551355
result = strToMatch( lang_tag , cur_lang_tag);
13561356
if( result == 0) {
13571357
efree( cur_lang_tag );
13581358
RETURN_FALSE;
13591359
}
1360-
cur_loc_range = reinterpret_cast<char *>(ecalloc( 1, strlen(loc_range ) + 1));
1360+
cur_loc_range = reinterpret_cast<char *>(ecalloc(1, loc_range_len + 1));
13611361
result = strToMatch( loc_range , cur_loc_range );
13621362
if( result == 0) {
13631363
efree( cur_lang_tag );
@@ -1370,7 +1370,7 @@ U_CFUNC PHP_FUNCTION(locale_filter_matches)
13701370

13711371
if( token && (token==cur_lang_tag) ){
13721372
/* check if the char. after match is SEPARATOR */
1373-
chrcheck = token + (strlen(cur_loc_range));
1373+
chrcheck = token + loc_range_len;
13741374
if( isIDSeparator(*chrcheck) || isEndOfTag(*chrcheck) ){
13751375
efree( cur_lang_tag );
13761376
efree( cur_loc_range );

0 commit comments

Comments
 (0)