Skip to content

Commit 380f854

Browse files
authored
random: Do not use ZVAL_DUP in Randomizer::shuffleArray() (php#16072)
PHP Internals Book says: > The ZVAL_DUP macro is similar to ZVAL_COPY, but will duplicate arrays, rather > than just incrementing their refcount. If you are using this macro, you are > almost certainly doing something very wrong. Replace this by an explicit call to `zend_array_dup()`, as done in `php_array_diff()`. Besides being more explicit in what is happening, this likely also results in better assembly.
1 parent 7f5e96d commit 380f854

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ext/random/randomizer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ PHP_METHOD(Random_Randomizer, shuffleArray)
356356
Z_PARAM_ARRAY(array)
357357
ZEND_PARSE_PARAMETERS_END();
358358

359-
ZVAL_DUP(return_value, array);
359+
RETVAL_ARR(zend_array_dup(Z_ARRVAL_P(array)));
360360
if (!php_array_data_shuffle(randomizer->engine, return_value)) {
361361
RETURN_THROWS();
362362
}

0 commit comments

Comments
 (0)