mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
sds.c new function sdsRemoveFreeSpace().
The new function is used in order to resize the string allocation so that only the minimal allocation possible is used, removing all the free space at the end of the string normally used to improve efficiency of concatenation operations.
This commit is contained in:
parent
529bde82ec
commit
9555f8f21b
12
src/sds.c
12
src/sds.c
@ -111,6 +111,18 @@ 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;
|
||||
}
|
||||
|
||||
/* 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.
|
||||
|
Loading…
Reference in New Issue
Block a user