diff options
author | antirez <antirez@gmail.com> | 2014-02-06 16:51:30 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-02-06 16:56:41 +0100 |
commit | c636fc6cd25e455a75dca24ac08ba736f62db6c8 (patch) | |
tree | 20c43054f404f201785306b3bbcb123724010f99 /sds.h | |
parent | c135fed2f965bf73b7672e86d85ff8bf5f740a4c (diff) | |
download | sds-c636fc6cd25e455a75dca24ac08ba736f62db6c8.tar.xz |
SDS Header pointer math rewritten in a more elegant form.
As suggested by unwind in the Hacker News site the calculation of "sh"
could be improved. In his own words:
"Since the entire idea is that the pointer on the left-hand side is to
the type whose size should be subtracted, I think it's better not to
repeat the type but to "lock it" to the pointer instead. This also (of
course) means we can drop the parenthesis with sizeof, since those are
only needed when its argument is a type name."
Diffstat (limited to 'sds.h')
-rw-r--r-- | sds.h | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -45,12 +45,12 @@ struct sdshdr { }; 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; } 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; } |