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

Function activeDefragStringOb

src/defrag.cpp:119–151  ·  view source on GitHub ↗

Defrag helper for robj and/or string objects * * returns NULL in case the allocation wasn't moved. * when it returns a non-null value, the old pointer was already released * and should NOT be accessed. */

Source from the content-addressed store, hash-verified

117 * when it returns a non-null value, the old pointer was already released
118 * and should NOT be accessed. */
119robj *activeDefragStringOb(robj* ob, long *defragged) {
120 robj *ret = NULL;
121 if (ob->getrefcount(std::memory_order_relaxed)!=1)
122 return NULL;
123
124 /* try to defrag robj (only if not an EMBSTR type (handled below). */
125 if (ob->type!=OBJ_STRING || ob->encoding!=OBJ_ENCODING_EMBSTR) {
126 if ((ret = (robj*)activeDefragAlloc(ob))) {
127 ob = ret;
128 (*defragged)++;
129 }
130 }
131
132 /* try to defrag string object */
133 if (ob->type == OBJ_STRING) {
134 if(ob->encoding==OBJ_ENCODING_RAW) {
135 sds newsds = activeDefragSds((sds)ptrFromObj(ob));
136 if (newsds) {
137 ob->m_ptr = newsds;
138 (*defragged)++;
139 }
140 } else if (ob->encoding==OBJ_ENCODING_EMBSTR) {
141 /* The sds is embedded in the object allocation, calculate the
142 * offset and update the pointer in the new allocation. */
143 if ((ret = (robj*)activeDefragAlloc(ob))) {
144 (*defragged)++;
145 }
146 } else if (ob->encoding!=OBJ_ENCODING_INT) {
147 serverPanic("Unknown string encoding");
148 }
149 }
150 return ret;
151}
152
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. */

Callers 5

activeDefragSdsDictFunction · 0.85
activeDefragListFunction · 0.85
defragKeyFunction · 0.85

Calls 4

activeDefragAllocFunction · 0.85
activeDefragSdsFunction · 0.85
ptrFromObjFunction · 0.85
getrefcountMethod · 0.80

Tested by

no test coverage detected