From f521498b43a8edcec01c88dc7361eaac460f2f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20S=C3=B6derqvist?= Date: Fri, 12 Feb 2021 12:20:54 +0100 Subject: [PATCH] Avoid useless copying in LINDEX command for reply --- src/t_list.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/t_list.c b/src/t_list.c index f019a7ec0..7b7cbe01f 100644 --- a/src/t_list.c +++ b/src/t_list.c @@ -324,7 +324,6 @@ void lindexCommand(client *c) { robj *o = lookupKeyReadOrReply(c,c->argv[1],shared.null[c->resp]); if (o == NULL || checkType(c,o,OBJ_LIST)) return; long index; - robj *value = NULL; if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != C_OK)) return; @@ -333,12 +332,10 @@ void lindexCommand(client *c) { quicklistEntry entry; if (quicklistIndex(o->ptr, index, &entry)) { if (entry.value) { - value = createStringObject((char*)entry.value,entry.sz); + addReplyBulkCBuffer(c, entry.value, entry.sz); } else { - value = createStringObjectFromLongLong(entry.longval); + addReplyBulkLongLong(c, entry.longval); } - addReplyBulk(c,value); - decrRefCount(value); } else { addReplyNull(c); }