MCPcopy Create free account
hub / github.com/F-Stack/f-stack / trimStringObjectIfNeeded

Function trimStringObjectIfNeeded

app/redis-6.2.6/src/object.c:429–435  ·  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

427 * string. This happens because SDS strings tend to overallocate to avoid
428 * wasting too much time in allocations when appending to the string. */
429void trimStringObjectIfNeeded(robj *o) {
430 if (o->encoding == OBJ_ENCODING_RAW &&
431 sdsavail(o->ptr) > sdslen(o->ptr)/10)
432 {
433 o->ptr = sdsRemoveFreeSpace(o->ptr);
434 }
435}
436
437/* Try to encode a string object in order to save space */
438robj *tryObjectEncoding(robj *o) {

Callers 2

tryObjectEncodingFunction · 0.85

Calls 3

sdsavailFunction · 0.85
sdslenFunction · 0.85
sdsRemoveFreeSpaceFunction · 0.85

Tested by

no test coverage detected