From 42b94c089c97b7f8d41ace2af5a90c161c1815f9 Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Sat, 17 Jan 2015 23:32:08 +0100 Subject: Revert "SDS Header pointer math rewritten in a more elegant form." This reverts commit c636fc6cd25e455a75dca24ac08ba736f62db6c8. This commit was just utterly senseless, all it does is make the code less clear for literally nothing. --- src/sds.c | 34 +++++++++++++++++----------------- src/sds.h | 4 ++-- 2 files changed, 19 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/sds.c b/src/sds.c index 74d2c44..1fdee37 100644 --- a/src/sds.c +++ b/src/sds.c @@ -49,9 +49,9 @@ sds sdsnewlen(const void *init, size_t initlen) { struct sdshdr *sh; if (init) { - sh = malloc(sizeof *sh+initlen+1); + sh = malloc(sizeof(struct sdshdr)+initlen+1); } else { - sh = calloc(sizeof *sh+initlen+1,1); + sh = calloc(sizeof(struct sdshdr)+initlen+1,1); } if (sh == NULL) return NULL; sh->len = initlen; @@ -100,7 +100,7 @@ void sdsfree(sds s) { * the output will be "6" as the string was modified but the logical length * remains 6 bytes. */ void sdsupdatelen(sds s) { - struct sdshdr *sh = (void*) (s-sizeof *sh);; + struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); int reallen = strlen(s); sh->free += (sh->len-reallen); sh->len = reallen; @@ -111,7 +111,7 @@ void sdsupdatelen(sds s) { * so that next append operations will not require allocations up to the * number of bytes previously available. */ void sdsclear(sds s) { - struct sdshdr *sh = (void*) (s-sizeof *sh);; + struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); sh->free += sh->len; sh->len = 0; sh->buf[0] = '\0'; @@ -130,13 +130,13 @@ sds sdsMakeRoomFor(sds s, size_t addlen) { if (free >= addlen) return s; len = sdslen(s); - sh = (void*) (s-sizeof *sh);; + sh = (void*) (s-(sizeof(struct sdshdr))); newlen = (len+addlen); if (newlen < SDS_MAX_PREALLOC) newlen *= 2; else newlen += SDS_MAX_PREALLOC; - newsh = realloc(sh, sizeof *newsh+newlen+1); + newsh = realloc(sh, sizeof(struct sdshdr)+newlen+1); if (newsh == NULL) return NULL; newsh->free = newlen - len; @@ -152,8 +152,8 @@ sds sdsMakeRoomFor(sds s, size_t addlen) { sds sdsRemoveFreeSpace(sds s) { struct sdshdr *sh; - sh = (void*) (s-sizeof *sh);; - sh = realloc(sh, sizeof *sh+sh->len+1); + sh = (void*) (s-(sizeof(struct sdshdr))); + sh = realloc(sh, sizeof(struct sdshdr)+sh->len+1); sh->free = 0; return sh->buf; } @@ -166,7 +166,7 @@ sds sdsRemoveFreeSpace(sds s) { * 4) The implicit null term. */ size_t sdsAllocSize(sds s) { - struct sdshdr *sh = (void*) (s-sizeof *sh);; + struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); return sizeof(*sh)+sh->len+sh->free+1; } @@ -195,7 +195,7 @@ size_t sdsAllocSize(sds s) { * sdsIncrLen(s, nread); */ void sdsIncrLen(sds s, int incr) { - struct sdshdr *sh = (void*) (s-sizeof *sh);; + struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); assert(sh->free >= incr); sh->len += incr; @@ -210,7 +210,7 @@ void sdsIncrLen(sds s, int incr) { * if the specified length is smaller than the current length, no operation * is performed. */ sds sdsgrowzero(sds s, size_t len) { - struct sdshdr *sh = (void*) (s-sizeof *sh); + struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr))); size_t totlen, curlen = sh->len; if (len <= curlen) return s; @@ -218,7 +218,7 @@ sds sdsgrowzero(sds s, size_t len) { if (s == NULL) return NULL; /* Make sure added region doesn't contain garbage */ - sh = (void*)(s-sizeof *sh); + sh = (void*)(s-(sizeof(struct sdshdr))); memset(s+curlen,0,(len-curlen+1)); /* also set trailing \0 byte */ totlen = sh->len+sh->free; sh->len = len; @@ -237,7 +237,7 @@ sds sdscatlen(sds s, const void *t, size_t len) { s = sdsMakeRoomFor(s,len); if (s == NULL) return NULL; - sh = (void*) (s-sizeof *sh);; + sh = (void*) (s-(sizeof(struct sdshdr))); memcpy(s+curlen, t, len); sh->len = curlen+len; sh->free = sh->free-len; @@ -264,13 +264,13 @@ sds sdscatsds(sds s, const sds t) { /* Destructively modify the sds string 's' to hold the specified binary * safe string pointed by 't' of length 'len' bytes. */ sds sdscpylen(sds s, const char *t, size_t len) { - struct sdshdr *sh = (void*) (s-sizeof *sh);; + struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); size_t totlen = sh->free+sh->len; if (totlen < len) { s = sdsMakeRoomFor(s,len-sh->len); if (s == NULL) return NULL; - sh = (void*) (s-sizeof *sh);; + sh = (void*) (s-(sizeof(struct sdshdr))); totlen = sh->free+sh->len; } memcpy(s, t, len); @@ -350,7 +350,7 @@ sds sdscatprintf(sds s, const char *fmt, ...) { * Output will be just "Hello World". */ void sdstrim(sds s, const char *cset) { - struct sdshdr *sh = (void*) (s-sizeof *sh);; + struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); char *start, *end, *sp, *ep; size_t len; @@ -382,7 +382,7 @@ void sdstrim(sds s, const char *cset) { * sdsrange(s,1,-1); => "ello World" */ void sdsrange(sds s, int start, int end) { - struct sdshdr *sh = (void*) (s-sizeof *sh);; + struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); size_t newlen, len = sdslen(s); if (len == 0) return; diff --git a/src/sds.h b/src/sds.h index 5080495..98124a5 100644 --- a/src/sds.h +++ b/src/sds.h @@ -42,12 +42,12 @@ struct sdshdr { }; static inline size_t sdslen(const sds s) { - struct sdshdr *sh = (void*)(s-sizeof *sh); + struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr))); return sh->len; } static inline size_t sdsavail(const sds s) { - struct sdshdr *sh = (void*)(s-sizeof *sh); + struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr))); return sh->free; } -- cgit v1.2.3-54-g00ecf