summaryrefslogtreecommitdiff
path: root/src/sds.c
diff options
context:
space:
mode:
author七飒 <charpty@gmail.com>2021-10-18 01:37:52 +0800
committerGitHub <noreply@github.com>2021-10-17 20:37:52 +0300
commitafd8c4e0073a55a47e55a36c9fcca332cf182228 (patch)
tree6bcc565d2edfdcc527c8f84609616ab2cff243f0 /src/sds.c
parent94fded4f4f9c3d52d69969c4a2a9d82786a3ac16 (diff)
downloadredis-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.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/sds.c b/src/sds.c
index 4279e92a5..a84c0d279 100644
--- a/src/sds.c
+++ b/src/sds.c
@@ -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);