Use less memory when emitting the protocol, by using more shared objects for commonly emitted parts of the protocol.

This commit is contained in:
antirez
2012-02-04 08:58:37 +01:00
parent ce8b772be7
commit 355f859134
5 changed files with 34 additions and 13 deletions

View File

@ -363,6 +363,18 @@ void addReplyDouble(redisClient *c, double d) {
void addReplyLongLongWithPrefix(redisClient *c, long long ll, char prefix) {
char buf[128];
int len;
/* Things like $3\r\n or *2\r\n are emitted very often by the protocol
* so we have a few shared objects to use if the integer is small
* like it is most of the times. */
if (prefix == '*' && ll < REDIS_SHARED_BULKHDR_LEN) {
addReply(c,shared.mbulkhdr[ll]);
return;
} else if (prefix == '$' && ll < REDIS_SHARED_BULKHDR_LEN) {
addReply(c,shared.bulkhdr[ll]);
return;
}
buf[0] = prefix;
len = ll2string(buf+1,sizeof(buf)-1,ll);
buf[len+1] = '\r';