Skip to content
1 change: 1 addition & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,5 @@ PHP 8.6 UPGRADE NOTES

- Standard:
. Improved performance of array_fill_keys().
. Improved performance of array_unshift().
. Improved performance of array_walk().
2 changes: 1 addition & 1 deletion Zend/tests/concat/concat_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (getenv('SKIP_PERF_SENSITIVE')) die("skip performance sensitive test");
$time = microtime(TRUE);

/* This might vary on Linux/Windows, so the worst case and also count in slow machines. */
$t_max = 1.0;
$t_max = 2.0;

$datas = array_fill(0, 220000, [
'000.000.000.000',
Expand Down
7 changes: 2 additions & 5 deletions ext/opcache/zend_file_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,13 @@ static int zend_file_cache_flock(int fd, int type)
(ptr) = (void*)((char*)buf + (size_t)(ptr)); \
} \
} while (0)

#define SERIALIZE_STR(ptr) do { \
if (ptr) { \
if (IS_ACCEL_INTERNED(ptr)) { \
(ptr) = zend_file_cache_serialize_interned((zend_string*)(ptr), info); \
} else { \
ZEND_ASSERT(IS_UNSERIALIZED(ptr)); \
/* script->corrupted shows if the script in SHM or not */ \
if (EXPECTED(script->corrupted)) { \
GC_ADD_FLAGS(ptr, IS_STR_INTERNED); \
GC_DEL_FLAGS(ptr, IS_STR_PERMANENT); \
} \
(ptr) = (void*)((char*)(ptr) - (char*)script->mem); \
} \
} \
Expand All @@ -164,6 +160,7 @@ static int zend_file_cache_flock(int fd, int type)
GC_ADD_FLAGS(ptr, IS_STR_INTERNED); \
GC_DEL_FLAGS(ptr, IS_STR_PERMANENT); \
} \
GC_DEL_FLAGS(ptr, IS_STR_CLASS_NAME_MAP_PTR); \
} \
} \
} while (0)
Expand Down
36 changes: 26 additions & 10 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -3743,18 +3743,34 @@ PHP_FUNCTION(array_unshift)
ZEND_PARSE_PARAMETERS_END();

zend_hash_init(&new_hash, zend_hash_num_elements(Z_ARRVAL_P(stack)) + argc, NULL, ZVAL_PTR_DTOR, 0);
for (uint32_t i = 0; i < argc; i++) {
Z_TRY_ADDREF(args[i]);
zend_hash_next_index_insert_new(&new_hash, &args[i]);
}

ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(stack), key, value) {
if (key) {
zend_hash_add_new(&new_hash, key, value);
} else {
zend_hash_next_index_insert_new(&new_hash, value);
if (HT_IS_PACKED(Z_ARRVAL_P(stack))) {
zend_hash_real_init_packed(&new_hash);

ZEND_HASH_FILL_PACKED(&new_hash) {
for (uint32_t i = 0; i < argc; i++) {
Z_TRY_ADDREF(args[i]);
ZEND_HASH_FILL_ADD(&args[i]);
}

ZEND_HASH_PACKED_FOREACH_VAL(Z_ARRVAL_P(stack), value) {
ZEND_HASH_FILL_ADD(value);
} ZEND_HASH_FOREACH_END();
} ZEND_HASH_FILL_END();
} else {
for (uint32_t i = 0; i < argc; i++) {
Z_TRY_ADDREF(args[i]);
zend_hash_next_index_insert_new(&new_hash, &args[i]);
}
} ZEND_HASH_FOREACH_END();

ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(stack), key, value) {
if (key) {
zend_hash_add_new(&new_hash, key, value);
} else {
zend_hash_next_index_insert_new(&new_hash, value);
}
} ZEND_HASH_FOREACH_END();
}

if (UNEXPECTED(HT_HAS_ITERATORS(Z_ARRVAL_P(stack)))) {
zend_hash_iterators_advance(Z_ARRVAL_P(stack), argc);
Expand Down