Commit f49f0a6f authored by antirez's avatar antirez
Browse files

SDS: make sdscatfmt() faster by pre-allocating a bit.

parent 40acb441
...@@ -603,6 +603,10 @@ sds sdscatfmt(sds s, char const *fmt, ...) { ...@@ -603,6 +603,10 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
long i; long i;
va_list ap; va_list ap;
/* To avoid continuous reallocations, let's start with a buffer that
* can hold at least two times the format string itself. It's not the
* best heuristic but seems to work in practice. */
s = sdsMakeRoomFor(s, initlen + strlen(fmt)*2);
va_start(ap,fmt); va_start(ap,fmt);
f = fmt; /* Next format specifier byte to process. */ f = fmt; /* Next format specifier byte to process. */
i = initlen; /* Position of the next byte to write to dest str. */ i = initlen; /* Position of the next byte to write to dest str. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment