Unverified Commit afd8c4e0 authored by 七飒's avatar 七飒 Committed by GitHub
Browse files

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: default avatarBo Cai <charpty@gmail.com>
parent 94fded4f
...@@ -827,7 +827,7 @@ sds sdstrim(sds s, const char *cset) { ...@@ -827,7 +827,7 @@ sds sdstrim(sds s, const char *cset) {
ep = end = s+sdslen(s)-1; ep = end = s+sdslen(s)-1;
while(sp <= end && strchr(cset, *sp)) sp++; while(sp <= end && strchr(cset, *sp)) sp++;
while(ep > sp && strchr(cset, *ep)) ep--; 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); if (s != sp) memmove(s, sp, len);
s[len] = '\0'; s[len] = '\0';
sdssetlen(s,len); sdssetlen(s,len);
......
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