diff options
author | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2010-11-04 13:26:22 +0100 |
---|---|---|
committer | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2010-11-04 13:26:22 +0100 |
commit | 9c4ee606d6cd04648ae4e34d42847ea65818448f (patch) | |
tree | 12c45f68fd8b9a66a80b34abe07cee5da865b68e | |
parent | 2e5e9a49fd1941296a6c94ca117e33bf2934bcfd (diff) |
Use strchr in a loop rather than strstr
-rw-r--r-- | hiredis.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -162,11 +162,20 @@ static char *readBytes(redisReader *r, unsigned int bytes) { return NULL; } +static char *seekNewline(char *s) { + /* Find pointer to \r\n without strstr */ + while(s != NULL && s[0] != '\r' && s[1] != '\n') + s = strchr(s,'\r'); + return s; +} + static char *readLine(redisReader *r, int *_len) { - char *p, *s = strstr(r->buf+r->pos,"\r\n"); + char *p, *s; int len; + + p = r->buf+r->pos; + s = seekNewline(p); if (s != NULL) { - p = r->buf+r->pos; len = s-(r->buf+r->pos); r->pos += len+2; /* skip \r\n */ if (_len) *_len = len; @@ -234,7 +243,7 @@ static int processBulkItem(redisReader *r) { unsigned long bytelen; p = r->buf+r->pos; - s = strstr(p,"\r\n"); + s = seekNewline(p); if (s != NULL) { p = r->buf+r->pos; bytelen = s-(r->buf+r->pos)+2; /* include \r\n */ |