Refactored manual computation of object length

This commit is contained in:
Madelyn Olson 2019-02-20 03:52:57 +00:00
parent 35ffbead5c
commit 9131fc56d6

View File

@ -636,23 +636,7 @@ void addReplyNullArray(client *c) {
/* Create the length prefix of a bulk reply, example: $2234 */ /* Create the length prefix of a bulk reply, example: $2234 */
void addReplyBulkLen(client *c, robj *obj) { void addReplyBulkLen(client *c, robj *obj) {
size_t len; size_t len = stringObjectLen(obj);
if (sdsEncodedObject(obj)) {
len = sdslen(obj->ptr);
} else {
long n = (long)obj->ptr;
/* Compute how many bytes will take this integer as a radix 10 string */
len = 1;
if (n < 0) {
len++;
n = -n;
}
while((n = n/10) != 0) {
len++;
}
}
if (len < OBJ_SHARED_BULKHDR_LEN) if (len < OBJ_SHARED_BULKHDR_LEN)
addReply(c,shared.bulkhdr[len]); addReply(c,shared.bulkhdr[len]);