From ad1b182fb82eec32f3f5d1da1c2da2e628439d02 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sun, 7 May 2017 05:03:41 +0000 Subject: Instead of starting a 'zero-sized' CBB at the size of the first addition to the CBB, then doubling, start with an initial size of 64 bytes. Almost all uses will exceed this size and we avoid multiple small recallocarray() calls during the initial usage. ok beck@ --- src/lib/libssl/bs_cbb.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libssl/bs_cbb.c b/src/lib/libssl/bs_cbb.c index 154a7964e6..dd1dc73d09 100644 --- a/src/lib/libssl/bs_cbb.c +++ b/src/lib/libssl/bs_cbb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bs_cbb.c,v 1.15 2017/04/14 15:20:55 jsing Exp $ */ +/* $OpenBSD: bs_cbb.c,v 1.16 2017/05/07 05:03:41 jsing Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -22,6 +22,8 @@ #include "bytestring.h" +#define CBB_INITIAL_SIZE 64 + static int cbb_init(CBB *cbb, uint8_t *buf, size_t cap) { @@ -49,10 +51,11 @@ CBB_init(CBB *cbb, size_t initial_capacity) memset(cbb, 0, sizeof(*cbb)); - if (initial_capacity > 0) { - if ((buf = malloc(initial_capacity)) == NULL) - return 0; - } + if (initial_capacity == 0) + initial_capacity = CBB_INITIAL_SIZE; + + if ((buf = malloc(initial_capacity)) == NULL) + return 0; if (!cbb_init(cbb, buf, initial_capacity)) { free(buf); -- cgit v1.2.3-55-g6feb