From ce1d7377723713346c5476e8c5d385a3e9b65fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20S=C3=B6derqvist?= Date: Fri, 12 Feb 2021 12:31:41 +0100 Subject: [PATCH] Use stack for decoding integer-encoded values in list push Less heap allocations when commands like LMOVE push integer values. --- src/t_list.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/t_list.c b/src/t_list.c index 7b7cbe01f..961f59ae4 100644 --- a/src/t_list.c +++ b/src/t_list.c @@ -41,10 +41,13 @@ void listTypePush(robj *subject, robj *value, int where) { if (subject->encoding == OBJ_ENCODING_QUICKLIST) { int pos = (where == LIST_HEAD) ? QUICKLIST_HEAD : QUICKLIST_TAIL; - value = getDecodedObject(value); - size_t len = sdslen(value->ptr); - quicklistPush(subject->ptr, value->ptr, len, pos); - decrRefCount(value); + if (value->encoding == OBJ_ENCODING_INT) { + char buf[32]; + ll2string(buf, 32, (long)value->ptr); + quicklistPush(subject->ptr, buf, strlen(buf), pos); + } else { + quicklistPush(subject->ptr, value->ptr, sdslen(value->ptr), pos); + } } else { serverPanic("Unknown list encoding"); }