Commit 6ea8e094 authored by antirez's avatar antirez
Browse files

sdsrange() does not need to return a value.

Actaully the string is modified in-place and a reallocation is never
needed, so there is no need to return the new sds string pointer as
return value of the function, that is now just "void".
parent 75b760a7
...@@ -1153,7 +1153,7 @@ void clusterWriteHandler(aeEventLoop *el, int fd, void *privdata, int mask) { ...@@ -1153,7 +1153,7 @@ void clusterWriteHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
handleLinkIOError(link); handleLinkIOError(link);
return; return;
} }
link->sndbuf = sdsrange(link->sndbuf,nwritten,-1); sdsrange(link->sndbuf,nwritten,-1);
if (sdslen(link->sndbuf) == 0) if (sdslen(link->sndbuf) == 0)
aeDeleteFileEvent(server.el, link->fd, AE_WRITABLE); aeDeleteFileEvent(server.el, link->fd, AE_WRITABLE);
} }
......
...@@ -866,7 +866,7 @@ int processInlineBuffer(redisClient *c) { ...@@ -866,7 +866,7 @@ int processInlineBuffer(redisClient *c) {
sdsfree(aux); sdsfree(aux);
/* Leave data after the first line of the query in the buffer */ /* Leave data after the first line of the query in the buffer */
c->querybuf = sdsrange(c->querybuf,querylen+2,-1); sdsrange(c->querybuf,querylen+2,-1);
/* Setup argv array on client structure */ /* Setup argv array on client structure */
if (c->argv) zfree(c->argv); if (c->argv) zfree(c->argv);
...@@ -895,7 +895,7 @@ static void setProtocolError(redisClient *c, int pos) { ...@@ -895,7 +895,7 @@ static void setProtocolError(redisClient *c, int pos) {
sdsfree(client); sdsfree(client);
} }
c->flags |= REDIS_CLOSE_AFTER_REPLY; c->flags |= REDIS_CLOSE_AFTER_REPLY;
c->querybuf = sdsrange(c->querybuf,pos,-1); sdsrange(c->querybuf,pos,-1);
} }
int processMultibulkBuffer(redisClient *c) { int processMultibulkBuffer(redisClient *c) {
...@@ -933,7 +933,7 @@ int processMultibulkBuffer(redisClient *c) { ...@@ -933,7 +933,7 @@ int processMultibulkBuffer(redisClient *c) {
pos = (newline-c->querybuf)+2; pos = (newline-c->querybuf)+2;
if (ll <= 0) { if (ll <= 0) {
c->querybuf = sdsrange(c->querybuf,pos,-1); sdsrange(c->querybuf,pos,-1);
return REDIS_OK; return REDIS_OK;
} }
...@@ -982,7 +982,7 @@ int processMultibulkBuffer(redisClient *c) { ...@@ -982,7 +982,7 @@ int processMultibulkBuffer(redisClient *c) {
* try to make it likely that it will start at c->querybuf * try to make it likely that it will start at c->querybuf
* boundary so that we can optimized object creation * boundary so that we can optimized object creation
* avoiding a large copy of data. */ * avoiding a large copy of data. */
c->querybuf = sdsrange(c->querybuf,pos,-1); sdsrange(c->querybuf,pos,-1);
pos = 0; pos = 0;
/* Hint the sds library about the amount of bytes this string is /* Hint the sds library about the amount of bytes this string is
* going to contain. */ * going to contain. */
...@@ -1021,7 +1021,7 @@ int processMultibulkBuffer(redisClient *c) { ...@@ -1021,7 +1021,7 @@ int processMultibulkBuffer(redisClient *c) {
} }
/* Trim to pos */ /* Trim to pos */
if (pos) c->querybuf = sdsrange(c->querybuf,pos,-1); if (pos) sdsrange(c->querybuf,pos,-1);
/* We're done when c->multibulk == 0 */ /* We're done when c->multibulk == 0 */
if (c->multibulklen == 0) return REDIS_OK; if (c->multibulklen == 0) return REDIS_OK;
......
...@@ -385,11 +385,11 @@ sds sdstrim(sds s, const char *cset) { ...@@ -385,11 +385,11 @@ sds sdstrim(sds s, const char *cset) {
* s = sdsnew("Hello World"); * s = sdsnew("Hello World");
* sdstrim(s,1,-1); => "ello Worl" * sdstrim(s,1,-1); => "ello Worl"
*/ */
sds sdsrange(sds s, int start, int end) { void sdsrange(sds s, int start, int end) {
struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr)));
size_t newlen, len = sdslen(s); size_t newlen, len = sdslen(s);
if (len == 0) return s; if (len == 0) return;
if (start < 0) { if (start < 0) {
start = len+start; start = len+start;
if (start < 0) start = 0; if (start < 0) start = 0;
...@@ -413,7 +413,6 @@ sds sdsrange(sds s, int start, int end) { ...@@ -413,7 +413,6 @@ sds sdsrange(sds s, int start, int end) {
sh->buf[newlen] = 0; sh->buf[newlen] = 0;
sh->free = sh->free+(sh->len-newlen); sh->free = sh->free+(sh->len-newlen);
sh->len = newlen; sh->len = newlen;
return s;
} }
/* Apply tolower() to every character of the sds string 's'. */ /* Apply tolower() to every character of the sds string 's'. */
......
...@@ -77,7 +77,7 @@ sds sdscatprintf(sds s, const char *fmt, ...); ...@@ -77,7 +77,7 @@ sds sdscatprintf(sds s, const char *fmt, ...);
#endif #endif
sds sdstrim(sds s, const char *cset); sds 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);
void sdsclear(sds s); void sdsclear(sds s);
int sdscmp(const sds s1, const sds s2); int sdscmp(const sds s1, const sds s2);
......
...@@ -1920,7 +1920,7 @@ void addReplySentinelRedisInstance(redisClient *c, sentinelRedisInstance *ri) { ...@@ -1920,7 +1920,7 @@ void addReplySentinelRedisInstance(redisClient *c, sentinelRedisInstance *ri) {
if (ri->flags & SRI_RECONF_DONE) flags = sdscat(flags,"reconf_done,"); if (ri->flags & SRI_RECONF_DONE) flags = sdscat(flags,"reconf_done,");
if (ri->flags & SRI_DEMOTE) flags = sdscat(flags,"demote,"); if (ri->flags & SRI_DEMOTE) flags = sdscat(flags,"demote,");
if (sdslen(flags) != 0) flags = sdsrange(flags,0,-2); /* remove last "," */ if (sdslen(flags) != 0) sdsrange(flags,0,-2); /* remove last "," */
addReplyBulkCString(c,flags); addReplyBulkCString(c,flags);
sdsfree(flags); sdsfree(flags);
fields++; fields++;
......
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