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

Function trimStringObjectIfNeeded

src/object.cpp:467–473  ·  view source on GitHub ↗

Optimize the SDS string inside the string object to require little space, * in case there is more than 10% of free space at the end of the SDS * string. This happens because SDS strings tend to overallocate to avoid * wasting too much time in allocations when appending to the string. */

Source from the content-addressed store, hash-verified

465 * string. This happens because SDS strings tend to overallocate to avoid
466 * wasting too much time in allocations when appending to the string. */
467void trimStringObjectIfNeeded(robj *o) {
468 if (o->encoding == OBJ_ENCODING_RAW &&
469 sdsavail(szFromObj(o)) > sdslen(szFromObj(o))/10)
470 {
471 o->m_ptr = sdsRemoveFreeSpace(szFromObj(o));
472 }
473}
474
475/* Try to encode a string object in order to save space */
476robj *tryObjectEncoding(robj *o) {

Callers 2

tryObjectEncodingFunction · 0.85

Calls 4

sdsavailFunction · 0.85
szFromObjFunction · 0.85
sdslenFunction · 0.85
sdsRemoveFreeSpaceFunction · 0.85

Tested by

no test coverage detected