Skip to content

Commit b932035

Browse files
iliaalmichael-grunder
authored andcommitted
perf: Avoid zero-fill in redis_key_prefix
redis_key_prefix used ecalloc to allocate the prefixed-key buffer, then immediately overwrote the entire allocation with two memcpy calls. The zero-fill was wasted work on every keyed argument when a prefix is set. Use emalloc and write the single trailing NUL explicitly.
1 parent ea8a867 commit b932035

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

library.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4483,9 +4483,10 @@ redis_key_prefix(RedisSock *redis_sock, char **key, size_t *key_len) {
44834483
}
44844484

44854485
ret_len = ZSTR_LEN(redis_sock->prefix) + *key_len;
4486-
ret = ecalloc(1 + ret_len, 1);
4486+
ret = emalloc(1 + ret_len);
44874487
memcpy(ret, ZSTR_VAL(redis_sock->prefix), ZSTR_LEN(redis_sock->prefix));
44884488
memcpy(ret + ZSTR_LEN(redis_sock->prefix), *key, *key_len);
4489+
ret[ret_len] = '\0';
44894490

44904491
*key = ret;
44914492
*key_len = ret_len;

0 commit comments

Comments
 (0)