From e5d50b236cd2ae81cbe901fe1f44e8c285f8f2dc Mon Sep 17 00:00:00 2001 From: wuYin Date: Thu, 1 Apr 2021 13:50:23 +0800 Subject: [PATCH] reuse existing range comparators in the zset (#8714) There are 2 common range comparators for skiplist: zslValueGteMin and zslValueLteMax, but they're not being reused in zslDeleteRangeByScore This is a small change to make code cleaner. --- src/t_zset.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/t_zset.c b/src/t_zset.c index dd65d3c67..323ace121 100644 --- a/src/t_zset.c +++ b/src/t_zset.c @@ -388,9 +388,8 @@ unsigned long zslDeleteRangeByScore(zskiplist *zsl, zrangespec *range, dict *dic x = zsl->header; for (i = zsl->level-1; i >= 0; i--) { - while (x->level[i].forward && (range->minex ? - x->level[i].forward->score <= range->min : - x->level[i].forward->score < range->min)) + while (x->level[i].forward && + !zslValueGteMin(x->level[i].forward->score, range)) x = x->level[i].forward; update[i] = x; } @@ -399,9 +398,7 @@ unsigned long zslDeleteRangeByScore(zskiplist *zsl, zrangespec *range, dict *dic x = x->level[0].forward; /* Delete nodes while in range. */ - while (x && - (range->maxex ? x->score < range->max : x->score <= range->max)) - { + while (x && zslValueLteMax(x->score, range)) { zskiplistNode *next = x->level[0].forward; zslDeleteNode(zsl,x,update); dictDelete(dict,x->ele);