MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / dictIterDefragEntry

Function dictIterDefragEntry

src/defrag.cpp:155–182  ·  view source on GitHub ↗

Defrag helper for dictEntries to be used during dict iteration (called on * each step). Returns a stat of how many pointers were moved. */

Source from the content-addressed store, hash-verified

153/* Defrag helper for dictEntries to be used during dict iteration (called on
154 * each step). Returns a stat of how many pointers were moved. */
155long dictIterDefragEntry(dictIterator *iter) {
156 /* This function is a little bit dirty since it messes with the internals
157 * of the dict and it's iterator, but the benefit is that it is very easy
158 * to use, and require no other changes in the dict. */
159 long defragged = 0;
160 dictht *ht;
161 /* Handle the next entry (if there is one), and update the pointer in the
162 * current entry. */
163 if (iter->nextEntry) {
164 dictEntry *newde = (dictEntry*)activeDefragAlloc(iter->nextEntry);
165 if (newde) {
166 defragged++;
167 iter->nextEntry = newde;
168 iter->entry->next = newde;
169 }
170 }
171 /* handle the case of the first entry in the hash bucket. */
172 ht = &iter->d->ht[iter->table];
173 if (ht->table[iter->index] == iter->entry) {
174 dictEntry *newde = (dictEntry*)activeDefragAlloc(iter->entry);
175 if (newde) {
176 iter->entry = newde;
177 ht->table[iter->index] = newde;
178 defragged++;
179 }
180 }
181 return defragged;
182}
183
184/* Defrag helper for dict main allocations (dict struct, and hash tables).
185 * receives a pointer to the dict* and implicitly updates it when the dict

Callers 2

activeDefragSdsDictFunction · 0.85

Calls 1

activeDefragAllocFunction · 0.85

Tested by

no test coverage detected