mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 09:00:51 +00:00
Add sdsnative()
Use the existing memory space for an SDS to convert it to a regular character buffer so we don't need to allocate duplicate space just to extract a usable buffer for native operations.
This commit is contained in:
parent
c6bf20c2a7
commit
e1619772db
11
src/sds.c
11
src/sds.c
@ -88,6 +88,17 @@ void sdsfree(sds s) {
|
|||||||
zfree(s-sizeof(struct sdshdr));
|
zfree(s-sizeof(struct sdshdr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Remove sds header so we can use buffer as malloc'd byte array.
|
||||||
|
* Returns the contents of 's' usable as a full malloc'd C string. */
|
||||||
|
char *sdsnative(sds s) {
|
||||||
|
if (!s) return NULL;
|
||||||
|
|
||||||
|
size_t len = sdslen(s);
|
||||||
|
char *base = s-sizeof(struct sdshdr);
|
||||||
|
memmove(base, s, len);
|
||||||
|
return zrealloc(base, len);
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the sds string length to the length as obtained with strlen(), so
|
/* Set the sds string length to the length as obtained with strlen(), so
|
||||||
* considering as content only up to the first null term character.
|
* considering as content only up to the first null term character.
|
||||||
*
|
*
|
||||||
|
@ -60,6 +60,7 @@ sds sdsempty(void);
|
|||||||
size_t sdslen(const sds s);
|
size_t sdslen(const sds s);
|
||||||
sds sdsdup(const sds s);
|
sds sdsdup(const sds s);
|
||||||
void sdsfree(sds s);
|
void sdsfree(sds s);
|
||||||
|
char *sdsnative(sds s);
|
||||||
size_t sdsavail(const sds s);
|
size_t sdsavail(const sds s);
|
||||||
sds sdsgrowzero(sds s, size_t len);
|
sds sdsgrowzero(sds s, size_t len);
|
||||||
sds sdscatlen(sds s, const void *t, size_t len);
|
sds sdscatlen(sds s, const void *t, size_t len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user