Commit 33452535 authored by antirez's avatar antirez Committed by Matt Stancliff
Browse files

Upgrade sds to latest version

SDS is now broken out of Redis into its own project, so include
the latest version from the SDS repo.

This is a backport of the Redis commit doing the same to the bundled hiredis:
https://github.com/antirez/redis/commit/320fa02b9b48ee1c63d88db6344fc0d328e24853
parent 4441fa35
...@@ -650,7 +650,7 @@ int redisReaderGetReply(redisReader *r, void **reply) { ...@@ -650,7 +650,7 @@ int redisReaderGetReply(redisReader *r, void **reply) {
/* Discard part of the buffer when we've consumed at least 1k, to avoid /* Discard part of the buffer when we've consumed at least 1k, to avoid
* doing unnecessary calls to memmove() in sds.c. */ * doing unnecessary calls to memmove() in sds.c. */
if (r->pos >= 1024) { if (r->pos >= 1024) {
r->buf = sdsrange(r->buf,r->pos,-1); sdsrange(r->buf,r->pos,-1);
r->pos = 0; r->pos = 0;
r->len = sdslen(r->buf); r->len = sdslen(r->buf);
} }
...@@ -1189,7 +1189,7 @@ int redisBufferWrite(redisContext *c, int *done) { ...@@ -1189,7 +1189,7 @@ int redisBufferWrite(redisContext *c, int *done) {
sdsfree(c->obuf); sdsfree(c->obuf);
c->obuf = sdsempty(); c->obuf = sdsempty();
} else { } else {
c->obuf = sdsrange(c->obuf,nwritten,-1); sdsrange(c->obuf,nwritten,-1);
} }
} }
} }
......
This diff is collapsed.
/* SDSLib, A C dynamic strings library /* SDS (Simple Dynamic Strings), A C dynamic strings library.
* *
* Copyright (c) 2006-2010, Salvatore Sanfilippo <antirez at gmail dot com> * Copyright (c) 2006-2014, Salvatore Sanfilippo <antirez at gmail dot com>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#ifndef __SDS_H #ifndef __SDS_H
#define __SDS_H #define __SDS_H
#define SDS_MAX_PREALLOC (1024*1024)
#include <sys/types.h> #include <sys/types.h>
#include <stdarg.h> #include <stdarg.h>
...@@ -43,12 +45,12 @@ struct sdshdr { ...@@ -43,12 +45,12 @@ struct sdshdr {
}; };
static inline size_t sdslen(const sds s) { static inline size_t sdslen(const sds s) {
struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr))); struct sdshdr *sh = (void*)(s-sizeof *sh);
return sh->len; return sh->len;
} }
static inline size_t sdsavail(const sds s) { static inline size_t sdsavail(const sds s) {
struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr))); struct sdshdr *sh = (void*)(s-sizeof *sh);
return sh->free; return sh->free;
} }
...@@ -58,12 +60,13 @@ sds sdsempty(void); ...@@ -58,12 +60,13 @@ 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);
size_t sdsavail(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);
sds sdscat(sds s, const char *t); sds sdscat(sds s, const char *t);
sds sdscpylen(sds s, char *t, size_t len); sds sdscatsds(sds s, const sds t);
sds sdscpy(sds s, char *t); sds sdscpylen(sds s, const char *t, size_t len);
sds sdscpy(sds s, const char *t);
sds sdscatvprintf(sds s, const char *fmt, va_list ap); sds sdscatvprintf(sds s, const char *fmt, va_list ap);
#ifdef __GNUC__ #ifdef __GNUC__
...@@ -73,16 +76,26 @@ sds sdscatprintf(sds s, const char *fmt, ...) ...@@ -73,16 +76,26 @@ sds sdscatprintf(sds s, const char *fmt, ...)
sds sdscatprintf(sds s, const char *fmt, ...); sds sdscatprintf(sds s, const char *fmt, ...);
#endif #endif
sds sdstrim(sds s, const char *cset); void sdstrim(sds s, const char *cset);
sds sdsrange(sds s, int start, int end); void sdsrange(sds s, int start, int end);
void sdsupdatelen(sds s); void sdsupdatelen(sds s);
int sdscmp(sds s1, sds s2); void sdsclear(sds s);
sds *sdssplitlen(char *s, int len, char *sep, int seplen, int *count); int sdscmp(const sds s1, const sds s2);
sds *sdssplitlen(const char *s, int len, const char *sep, int seplen, int *count);
void sdsfreesplitres(sds *tokens, int count); void sdsfreesplitres(sds *tokens, int count);
void sdstolower(sds s); void sdstolower(sds s);
void sdstoupper(sds s); void sdstoupper(sds s);
sds sdsfromlonglong(long long value); sds sdsfromlonglong(long long value);
sds sdscatrepr(sds s, char *p, size_t len); sds sdscatrepr(sds s, const char *p, size_t len);
sds *sdssplitargs(char *line, int *argc); sds *sdssplitargs(const char *line, int *argc);
sds sdsmapchars(sds s, const char *from, const char *to, size_t setlen);
sds sdsjoin(char **argv, int argc, char *sep, size_t seplen);
sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen);
/* Low level functions exposed to the user API */
sds sdsMakeRoomFor(sds s, size_t addlen);
void sdsIncrLen(sds s, int incr);
sds sdsRemoveFreeSpace(sds s);
size_t sdsAllocSize(sds s);
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment