Destroy an entire dictionary */
| 801 | |
| 802 | /* Destroy an entire dictionary */ |
| 803 | int _dictClear(dict *d, dictht *ht, void(callback)(void *)) { |
| 804 | unsigned long i; |
| 805 | |
| 806 | /* Free all the elements */ |
| 807 | for (i = 0; i < ht->size && ht->used > 0; i++) { |
| 808 | dictEntry *he, *nextHe; |
| 809 | |
| 810 | if (callback && (i & 65535) == 0) callback(d->privdata); |
| 811 | |
| 812 | if ((he = ht->table[i]) == NULL) continue; |
| 813 | dictEntry *deNull = nullptr; |
| 814 | __atomic_store(&ht->table[i], &deNull, __ATOMIC_RELEASE); |
| 815 | while(he) { |
| 816 | nextHe = he->next; |
| 817 | if (d->asyncdata && (ssize_t)i < d->rehashidx) { |
| 818 | dictFreeVal(d, he); |
| 819 | he->v.val = nullptr; |
| 820 | he->next = d->asyncdata->deGCList; |
| 821 | d->asyncdata->deGCList = he; |
| 822 | } else { |
| 823 | dictFreeKey(d, he); |
| 824 | dictFreeVal(d, he); |
| 825 | zfree(he); |
| 826 | } |
| 827 | ht->used--; |
| 828 | he = nextHe; |
| 829 | } |
| 830 | } |
| 831 | /* Free the table and the allocated cache structure */ |
| 832 | asyncFreeDictTable(ht->table); |
| 833 | /* Re-initialize the table */ |
| 834 | _dictReset(ht); |
| 835 | return DICT_OK; /* never fails */ |
| 836 | } |
| 837 | |
| 838 | /* Clear & Release the hash table */ |
| 839 | void dictRelease(dict *d) |
no test coverage detected