mirror of
https://github.com/phpredis/phpredis.git
synced 2026-06-19 07:35:31 +00:00
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.
This commit is contained in:
committed by
Michael Grunder
parent
ea8a86727e
commit
b9320359e8
@@ -4483,9 +4483,10 @@ redis_key_prefix(RedisSock *redis_sock, char **key, size_t *key_len) {
|
||||
}
|
||||
|
||||
ret_len = ZSTR_LEN(redis_sock->prefix) + *key_len;
|
||||
ret = ecalloc(1 + ret_len, 1);
|
||||
ret = emalloc(1 + ret_len);
|
||||
memcpy(ret, ZSTR_VAL(redis_sock->prefix), ZSTR_LEN(redis_sock->prefix));
|
||||
memcpy(ret + ZSTR_LEN(redis_sock->prefix), *key, *key_len);
|
||||
ret[ret_len] = '\0';
|
||||
|
||||
*key = ret;
|
||||
*key_len = ret_len;
|
||||
|
||||
Reference in New Issue
Block a user