From 02ba1789a37763d464dfe7edf55a6a6c176610d3 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Fri, 21 Apr 2017 11:33:15 -0400 Subject: [PATCH] Avoid needless C gymnastics. This can just be a bog-standard loop. The compiler should be plenty smart enough to transform it into whatever it likes. Change-Id: I7b782dd2a11902f6e5c9902d9624be26eee5c959 Reviewed-on: https://boringssl-review.googlesource.com/15366 Reviewed-by: David Benjamin Commit-Queue: David Benjamin CQ-Verified: CQ bot account: commit-bot@chromium.org --- crypto/bn/ctx.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/crypto/bn/ctx.c b/crypto/bn/ctx.c index bca6619a..d1400a3f 100644 --- a/crypto/bn/ctx.c +++ b/crypto/bn/ctx.c @@ -242,13 +242,8 @@ static void BN_POOL_init(BN_POOL *p) { static void BN_POOL_finish(BN_POOL *p) { while (p->head) { - unsigned int loop = 0; - BIGNUM *bn = p->head->vals; - while (loop++ < BN_CTX_POOL_SIZE) { - if (bn->d) { - BN_clear_free(bn); - } - bn++; + for (size_t i = 0; i < BN_CTX_POOL_SIZE; i++) { + BN_clear_free(&p->head->vals[i]); } p->current = p->head->next; @@ -259,17 +254,14 @@ static void BN_POOL_finish(BN_POOL *p) { static BIGNUM *BN_POOL_get(BN_POOL *p) { if (p->used == p->size) { - BIGNUM *bn; - unsigned int loop = 0; BN_POOL_ITEM *item = OPENSSL_malloc(sizeof(BN_POOL_ITEM)); if (!item) { return NULL; } /* Initialise the structure */ - bn = item->vals; - while (loop++ < BN_CTX_POOL_SIZE) { - BN_init(bn++); + for (size_t i = 0; i < BN_CTX_POOL_SIZE; i++) { + BN_init(&item->vals[i]); } item->prev = p->tail;