Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint32_t idx, j, n_elems;
- Bucket *p, temp;
- HashTable *hash;
- zend_long rnd_idx, n_left;
- n_elems = zend_hash_num_elements(Z_ARRVAL_P(array));
- if (n_elems < 1) {
- return;
- }
- hash = Z_ARRVAL_P(array);
- n_left = n_elems;
- if (EXPECTED(hash->u.v.nIteratorsCount == 0)) {
- if (hash->nNumUsed != hash->nNumOfElements) {
- for (j = 0, idx = 0; idx < hash->nNumUsed; idx++) {
- p = hash->arData + idx;
- if (Z_TYPE(p->val) == IS_UNDEF) continue;
- if (j != idx) {
- hash->arData[j] = *p;
- }
- j++;
- }
- }
- while (--n_left) {
- rnd_idx = php_rand();
- RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX);
- if (rnd_idx != n_left) {
- temp = hash->arData[n_left];
- hash->arData[n_left] = hash->arData[rnd_idx];
- hash->arData[rnd_idx] = temp;
- }
- }
- } else {
- uint32_t iter_pos = zend_hash_iterators_lower_pos(hash, 0);
- if (hash->nNumUsed != hash->nNumOfElements) {
- for (j = 0, idx = 0; idx < hash->nNumUsed; idx++) {
- p = hash->arData + idx;
- if (Z_TYPE(p->val) == IS_UNDEF) continue;
- if (j != idx) {
- hash->arData[j] = *p;
- if (idx == iter_pos) {
- zend_hash_iterators_update(hash, idx, j);
- iter_pos = zend_hash_iterators_lower_pos(hash, iter_pos + 1);
- }
- }
- j++;
- }
- }
- while (--n_left) {
- rnd_idx = php_rand();
- RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX);
- if (rnd_idx != n_left) {
- temp = hash->arData[n_left];
- hash->arData[n_left] = hash->arData[rnd_idx];
- hash->arData[rnd_idx] = temp;
- zend_hash_iterators_update(hash, rnd_idx, n_left);
- }
- }
- }
- HANDLE_BLOCK_INTERRUPTIONS();
- hash->nNumUsed = n_elems;
- hash->nInternalPointer = 0;
- for (j = 0; j < n_elems; j++) {
- p = hash->arData + j;
- if (p->key) {
- zend_string_release(p->key);
- }
- p->h = j;
- p->key = NULL;
- }
- hash->nNextFreeElement = n_elems;
- if (!(hash->u.flags & HASH_FLAG_PACKED)) {
- zend_hash_to_packed(hash);
- }
- HANDLE_UNBLOCK_INTERRUPTIONS();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement