diff options
author | 七飒 <charpty@gmail.com> | 2021-10-18 01:37:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-17 20:37:52 +0300 |
commit | afd8c4e0073a55a47e55a36c9fcca332cf182228 (patch) | |
tree | 6bcc565d2edfdcc527c8f84609616ab2cff243f0 /src/sds.c | |
parent | 94fded4f4f9c3d52d69969c4a2a9d82786a3ac16 (diff) | |
download | redis-afd8c4e0073a55a47e55a36c9fcca332cf182228.tar.gz |
sdstrim remove excessive check (#4045)
there is no need to compare the value of ep and sp
```
sp = start = s;
// the only way that make ep > sp is sdslen(s) == 0
// so when ep > sp,must exist ep-sp == -1
ep = end = s+sdslen(s)-1;
while(sp <= end && strchr(cset, *sp)) sp++;
while(ep > sp && strchr(cset, *ep)) ep--;
// -1 + 1 already equals 0
len = (sp > ep) ? 0 : ((ep-sp)+1);
```
Signed-off-by: Bo Cai <charpty@gmail.com>
Diffstat (limited to 'src/sds.c')
-rw-r--r-- | src/sds.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -827,7 +827,7 @@ sds sdstrim(sds s, const char *cset) { ep = end = s+sdslen(s)-1; while(sp <= end && strchr(cset, *sp)) sp++; while(ep > sp && strchr(cset, *ep)) ep--; - len = (sp > ep) ? 0 : ((ep-sp)+1); + len = (ep-sp)+1; if (s != sp) memmove(s, sp, len); s[len] = '\0'; sdssetlen(s,len); |