php-ext-orng
php-ext-orng copied to clipboard
Duplicate code in arrayRand method.
trafficstars
https://github.com/zeriyoshi/php-ext-orng/blob/master/rng/glibcrand.c#L287 https://github.com/zeriyoshi/php-ext-orng/blob/master/rng/mt19937.c#L222 https://github.com/zeriyoshi/php-ext-orng/blob/master/rng/xorshift128plus.c#L176
For compatibility with PHP 7.3, the internal implementation of arrayRand() is outdated to PHP 8.0.
But, it has been verified that the results to correct in tests.
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) {
zval zv;
/* We can't use zend_hash_index_find()
* because the array may have string keys or gaps. */
ZEND_HASH_FOREACH_KEY(Z_ARRVAL_P(input), num_key, string_key) {
if (zend_bitset_in(bitset, i) ^ negative_bitset) {
if (string_key) {
// ZEND_HASH_FILL_SET_STR_COPY(string_key);
ZVAL_STR_COPY(&zv, string_key);
} else {
// ZEND_HASH_FILL_SET_LONG(num_key);
ZVAL_LONG(&zv, num_key);
}
// ZEND_HASH_FILL_NEXT();
ZEND_HASH_FILL_ADD(&zv);
}
i++;
} ZEND_HASH_FOREACH_END();
} ZEND_HASH_FILL_END();
free_alloca(bitset, use_heap);