From cf1d49adbfd1713bd832ade9d57ffdc032e40c33 Mon Sep 17 00:00:00 2001 From: ZhaolongLi <0x4f4f4f4f@gmail.com> Date: Wed, 30 Jun 2021 13:21:19 +0800 Subject: [PATCH] Simplify logic in raxSeek, eliminate it->key reassembly on gt and lt (#9115) In the original version, the operation of traversing the stack only seems to reconstruct the key that does not contain the current node. But in fact We have got the matched length and splitpos in the key in the raxlowwalk, so I think we can simplify the logic of this part. Co-authored-by: lizhaolong.lzl --- src/rax.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/src/rax.c b/src/rax.c index a82b2e7eee..580a2dd89b 100644 --- a/src/rax.c +++ b/src/rax.c @@ -1576,30 +1576,8 @@ int raxSeek(raxIterator *it, const char *op, unsigned char *ele, size_t len) { } else if (lt || gt) { /* Exact key not found or eq flag not set. We have to set as current * key the one represented by the node we stopped at, and perform - * a next/prev operation to seek. To reconstruct the key at this node - * we start from the parent and go to the current node, accumulating - * the characters found along the way. */ - if (!raxStackPush(&it->stack,it->node)) return 0; - for (size_t j = 1; j < it->stack.items; j++) { - raxNode *parent = it->stack.stack[j-1]; - raxNode *child = it->stack.stack[j]; - if (parent->iscompr) { - if (!raxIteratorAddChars(it,parent->data,parent->size)) - return 0; - } else { - raxNode **cp = raxNodeFirstChildPtr(parent); - unsigned char *p = parent->data; - while(1) { - raxNode *aux; - memcpy(&aux,cp,sizeof(aux)); - if (aux == child) break; - cp++; - p++; - } - if (!raxIteratorAddChars(it,p,1)) return 0; - } - } - raxStackPop(&it->stack); + * a next/prev operation to seek. */ + raxIteratorAddChars(it, ele, i-splitpos); /* We need to set the iterator in the correct state to call next/prev * step in order to seek the desired element. */