Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4122daa

Browse files
ext/date: various array optimisations. (php#18382)
1 parent ba4567a commit 4122daa

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

‎ext/date/php_date.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ PHP_FUNCTION(localtime)
14081408
ts->zone_type = TIMELIB_ZONETYPE_ID;
14091409
timelib_unixtime2local(ts, (timelib_sll) timestamp);
14101410

1411-
array_init(return_value);
1411+
array_init_size(return_value, 9);
14121412

14131413
if (associative) {
14141414
add_assoc_long(return_value, "tm_sec", ts->s);
@@ -1421,6 +1421,7 @@ PHP_FUNCTION(localtime)
14211421
add_assoc_long(return_value, "tm_yday", timelib_day_of_year(ts->y, ts->m, ts->d));
14221422
add_assoc_long(return_value, "tm_isdst", ts->dst);
14231423
} else {
1424+
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
14241425
add_next_index_long(return_value, ts->s);
14251426
add_next_index_long(return_value, ts->i);
14261427
add_next_index_long(return_value, ts->h);
@@ -1462,7 +1463,7 @@ PHP_FUNCTION(getdate)
14621463
ts->zone_type = TIMELIB_ZONETYPE_ID;
14631464
timelib_unixtime2local(ts, (timelib_sll) timestamp);
14641465

1465-
array_init(return_value);
1466+
array_init_size(return_value, 11);
14661467

14671468
add_assoc_long(return_value, "seconds", ts->s);
14681469
add_assoc_long(return_value, "minutes", ts->i);
@@ -3059,14 +3060,14 @@ static void zval_from_error_container(zval *z, const timelib_error_container *er
30593060
zval element;
30603061

30613062
add_assoc_long(z, "warning_count", error->warning_count);
3062-
array_init(&element);
3063+
array_init_size(&element, error->warning_count);
30633064
for (i = 0; i < error->warning_count; i++) {
30643065
add_index_string(&element, error->warning_messages[i].position, error->warning_messages[i].message);
30653066
}
30663067
add_assoc_zval(z, "warnings", &element);
30673068

30683069
add_assoc_long(z, "error_count", error->error_count);
3069-
array_init(&element);
3070+
array_init_size(&element, error->error_count);
30703071
for (i = 0; i < error->error_count; i++) {
30713072
add_index_string(&element, error->error_messages[i].position, error->error_messages[i].message);
30723073
}
@@ -4275,7 +4276,7 @@ PHP_FUNCTION(timezone_transitions_get)
42754276
}
42764277

42774278
#define add_nominal() \
4278-
array_init(&element); \
4279+
array_init_size(&element, 5); \
42794280
add_assoc_long(&element, "ts", timestamp_begin); \
42804281
add_assoc_str(&element, "time", php_format_date(DATE_FORMAT_ISO8601_LARGE_YEAR, 13, timestamp_begin, 0)); \
42814282
add_assoc_long(&element, "offset", tzobj->tzi.tz->type[0].offset); \
@@ -4284,7 +4285,7 @@ PHP_FUNCTION(timezone_transitions_get)
42844285
add_next_index_zval(return_value, &element);
42854286

42864287
#define add(i,ts) \
4287-
array_init(&element); \
4288+
array_init_size(&element, 5); \
42884289
add_assoc_long(&element, "ts", ts); \
42894290
add_assoc_str(&element, "time", php_format_date(DATE_FORMAT_ISO8601_LARGE_YEAR, 13, ts, 0)); \
42904291
add_assoc_long(&element, "offset", tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i]].offset); \
@@ -4293,7 +4294,7 @@ PHP_FUNCTION(timezone_transitions_get)
42934294
add_next_index_zval(return_value, &element);
42944295

42954296
#define add_by_index(i,ts) \
4296-
array_init(&element); \
4297+
array_init_size(&element, 5); \
42974298
add_assoc_long(&element, "ts", ts); \
42984299
add_assoc_str(&element, "time", php_format_date(DATE_FORMAT_ISO8601_LARGE_YEAR, 13, ts, 0)); \
42994300
add_assoc_long(&element, "offset", tzobj->tzi.tz->type[i].offset); \
@@ -4302,7 +4303,7 @@ PHP_FUNCTION(timezone_transitions_get)
43024303
add_next_index_zval(return_value, &element);
43034304

43044305
#define add_from_tto(to,ts) \
4305-
array_init(&element); \
4306+
array_init_size(&element, 5); \
43064307
add_assoc_long(&element, "ts", ts); \
43074308
add_assoc_str(&element, "time", php_format_date(DATE_FORMAT_ISO8601_LARGE_YEAR, 13, ts, 0)); \
43084309
add_assoc_long(&element, "offset", (to)->offset); \
@@ -5336,6 +5337,7 @@ PHP_FUNCTION(timezone_identifiers_list)
53365337
table = timelib_timezone_identifiers_list((timelib_tzdb*) tzdb, &item_count);
53375338

53385339
array_init(return_value);
5340+
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
53395341

53405342
for (i = 0; i < item_count; ++i) {
53415343
if (what == PHP_DATE_TIMEZONE_PER_COUNTRY) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /