From: Igor Putovny Date: Thu, 24 Apr 2025 12:50:24 +0000 (+0200) Subject: Refactor add_bucket() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bff1927a414aef5f480fd5a030d2aa22fb552cc;p=thirdparty%2Fbird.git Refactor add_bucket() --- diff --git a/proto/aggregator/aggregator.c b/proto/aggregator/aggregator.c index c14675b37..824c97df2 100644 --- a/proto/aggregator/aggregator.c +++ b/proto/aggregator/aggregator.c @@ -44,7 +44,6 @@ extern linpool *rte_update_pool; /* * Add @bucket to the list of bucket pointers in @p to position @bucket.id */ -// TODO: enable to reset bucket ptr? static void aggregator_add_bucket(struct aggregator_proto *p, struct aggregator_bucket *bucket) { @@ -52,29 +51,28 @@ aggregator_add_bucket(struct aggregator_proto *p, struct aggregator_bucket *buck ASSERT_DIE(p->bucket_list != NULL); ASSERT_DIE(bucket != NULL); - /* Bucket is already in the list */ - if (bucket->id < p->bucket_list_size && p->bucket_list[bucket->id]) + /* Save bucket pointer */ + if (bucket->id < p->bucket_list_size) + { + p->bucket_list[bucket->id] = bucket; return; + } + /* Reallocate if more space is needed */ const size_t old_size = p->bucket_list_size; - /* Reallocate if more space is needed */ - if (bucket->id >= p->bucket_list_size) - { - while (bucket->id >= p->bucket_list_size) - p->bucket_list_size *= 2; + while (bucket->id >= p->bucket_list_size) + p->bucket_list_size *= 2; - ASSERT_DIE(old_size < p->bucket_list_size); + ASSERT_DIE(old_size < p->bucket_list_size); - p->bucket_list = mb_realloc(p->bucket_list, sizeof(p->bucket_list[0]) * p->bucket_list_size); - memset(&p->bucket_list[old_size], 0, sizeof(p->bucket_list[0]) * (p->bucket_list_size - old_size)); - } + p->bucket_list = mb_realloc(p->bucket_list, sizeof(p->bucket_list[0]) * p->bucket_list_size); + memset(&p->bucket_list[old_size], 0, sizeof(p->bucket_list[0]) * (p->bucket_list_size - old_size)); ASSERT_DIE(bucket->id < p->bucket_list_size); ASSERT_DIE(p->bucket_list[bucket->id] == NULL); p->bucket_list[bucket->id] = bucket; - p->bucket_list_count++; } /* @@ -790,7 +788,6 @@ aggregator_init(struct proto_config *CF) p->logging = cf->logging; p->bucket_list = NULL; p->bucket_list_size = 0; - p->bucket_list_count = 0; P->rt_notify = aggregator_rt_notify; P->preexport = aggregator_preexport; @@ -891,7 +888,6 @@ aggregator_start(struct proto *P) ASSERT_DIE(p->bucket_list == NULL); ASSERT_DIE(p->bucket_list_size == 0); - ASSERT_DIE(p->bucket_list_count == 0); p->bucket_list_size = BUCKET_LIST_INIT_SIZE; p->bucket_list = mb_allocz(P->pool, sizeof(p->bucket_list[0]) * p->bucket_list_size); @@ -929,7 +925,6 @@ aggregator_cleanup(struct proto *P) p->bucket_list = NULL; p->bucket_list_size = 0; - p->bucket_list_count = 0; p->rte_withdrawal_stack = NULL; p->rte_withdrawal_count = 0; diff --git a/proto/aggregator/aggregator.h b/proto/aggregator/aggregator.h index 9ff844f1a..758d7d686 100644 --- a/proto/aggregator/aggregator.h +++ b/proto/aggregator/aggregator.h @@ -94,7 +94,6 @@ struct aggregator_proto { /* Array of bucket pointers */ struct aggregator_bucket **bucket_list; uint bucket_list_size; - int bucket_list_count; /* Route withdrawal */ struct rte_withdrawal_item *rte_withdrawal_stack;