X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/8562798308391d489016b3995d438b6187b5980a..1858da2faae3b6a8becf4f7eef3f712d6e4b986b:/src/sds.c?ds=sidebyside diff --git a/src/sds.c b/src/sds.c index 092a431e..bc6aa6b2 100644 --- a/src/sds.c +++ b/src/sds.c @@ -111,6 +111,24 @@ sds sdsMakeRoomFor(sds s, size_t addlen) { return newsh->buf; } +/* Reallocate the sds string so that it has no free space at the end. The + * contained string remains not altered, but next concatenation operations + * will require a reallocation. */ +sds sdsRemoveFreeSpace(sds s) { + struct sdshdr *sh; + + sh = (void*) (s-(sizeof(struct sdshdr))); + sh = zrealloc(sh, sizeof(struct sdshdr)+sh->len+1); + sh->free = 0; + return sh->buf; +} + +size_t sdsAllocSize(sds s) { + struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); + + return sizeof(*sh)+sh->len+sh->free+1; +} + /* Increment the sds length and decrements the left free space at the * end of the string accordingly to 'incr'. Also set the null term * in the new end of the string.