Advertisement
voodooKobra

Untitled

Feb 27th, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1.  
  2. uint32_t idx, j, n_elems;
  3. Bucket *p, temp;
  4. HashTable *hash;
  5. zend_long rnd_idx, n_left;
  6.  
  7. n_elems = zend_hash_num_elements(Z_ARRVAL_P(array));
  8.  
  9. if (n_elems < 1) {
  10. return;
  11. }
  12.  
  13. hash = Z_ARRVAL_P(array);
  14. n_left = n_elems;
  15.  
  16. if (EXPECTED(hash->u.v.nIteratorsCount == 0)) {
  17. if (hash->nNumUsed != hash->nNumOfElements) {
  18. for (j = 0, idx = 0; idx < hash->nNumUsed; idx++) {
  19. p = hash->arData + idx;
  20. if (Z_TYPE(p->val) == IS_UNDEF) continue;
  21. if (j != idx) {
  22. hash->arData[j] = *p;
  23. }
  24. j++;
  25. }
  26. }
  27. while (--n_left) {
  28. rnd_idx = php_rand();
  29. RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX);
  30. if (rnd_idx != n_left) {
  31. temp = hash->arData[n_left];
  32. hash->arData[n_left] = hash->arData[rnd_idx];
  33. hash->arData[rnd_idx] = temp;
  34. }
  35. }
  36. } else {
  37. uint32_t iter_pos = zend_hash_iterators_lower_pos(hash, 0);
  38.  
  39. if (hash->nNumUsed != hash->nNumOfElements) {
  40. for (j = 0, idx = 0; idx < hash->nNumUsed; idx++) {
  41. p = hash->arData + idx;
  42. if (Z_TYPE(p->val) == IS_UNDEF) continue;
  43. if (j != idx) {
  44. hash->arData[j] = *p;
  45. if (idx == iter_pos) {
  46. zend_hash_iterators_update(hash, idx, j);
  47. iter_pos = zend_hash_iterators_lower_pos(hash, iter_pos + 1);
  48. }
  49. }
  50. j++;
  51. }
  52. }
  53. while (--n_left) {
  54. rnd_idx = php_rand();
  55. RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX);
  56. if (rnd_idx != n_left) {
  57. temp = hash->arData[n_left];
  58. hash->arData[n_left] = hash->arData[rnd_idx];
  59. hash->arData[rnd_idx] = temp;
  60. zend_hash_iterators_update(hash, rnd_idx, n_left);
  61. }
  62. }
  63. }
  64. HANDLE_BLOCK_INTERRUPTIONS();
  65. hash->nNumUsed = n_elems;
  66. hash->nInternalPointer = 0;
  67.  
  68. for (j = 0; j < n_elems; j++) {
  69. p = hash->arData + j;
  70. if (p->key) {
  71. zend_string_release(p->key);
  72. }
  73. p->h = j;
  74. p->key = NULL;
  75. }
  76. hash->nNextFreeElement = n_elems;
  77. if (!(hash->u.flags & HASH_FLAG_PACKED)) {
  78. zend_hash_to_packed(hash);
  79. }
  80. HANDLE_UNBLOCK_INTERRUPTIONS();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement