Make slight SSL performance improvements

This commit is contained in:
Justine Tunney 2021-07-08 21:54:21 -07:00
parent 4178896aa0
commit fe881982b5
6 changed files with 100 additions and 19 deletions

View file

@ -68,14 +68,14 @@ int AppendFmt(struct Buffer *b, const char *fmt, ...) {
va_start(va, fmt);
va_copy(vb, va);
n = vsnprintf(b->p + b->i, b->n - b->i, fmt, va);
if (n >= b->n - b->i) {
if (b->i + n + 1 > b->n) {
do {
if (b->n) {
b->n += b->n >> 1; /* the proper way to grow w/ amortization */
b->n += b->n >> 1;
} else {
b->n = 16;
}
} while (b->i + n > b->n);
} while (b->i + n + 1 > b->n);
b->p = realloc(b->p, b->n);
vsnprintf(b->p + b->i, b->n - b->i, fmt, vb);
}