From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 05/13] gc: fold gc_consumer_new and gc_consumer_delete Date: Thu, 4 Oct 2018 20:20:07 +0300 Message-Id: <174ff75d6da63c095fc742a4bf857f66056e4952.1538671546.git.vdavydov.dev@gmail.com> In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: gc_consumer_new is used in one place while gc_consumer_delete is used in two places, but it's a one-liner. Let's fold them to make the code flow more straightforward. --- src/box/gc.c | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/src/box/gc.c b/src/box/gc.c index 7de50e84..449416b5 100644 --- a/src/box/gc.c +++ b/src/box/gc.c @@ -71,31 +71,6 @@ gc_consumer_cmp(const struct gc_consumer *a, const struct gc_consumer *b) rb_gen(MAYBE_UNUSED static inline, gc_tree_, gc_tree_t, struct gc_consumer, node, gc_consumer_cmp); -/** Allocate a consumer object. */ -static struct gc_consumer * -gc_consumer_new(const char *name, const struct vclock *vclock, - enum gc_consumer_type type) -{ - struct gc_consumer *consumer = calloc(1, sizeof(*consumer)); - if (consumer == NULL) { - diag_set(OutOfMemory, sizeof(*consumer), - "malloc", "struct gc_consumer"); - return NULL; - } - snprintf(consumer->name, GC_NAME_MAX, "%s", name); - vclock_copy(&consumer->vclock, vclock); - consumer->type = type; - return consumer; -} - -/** Free a consumer object. */ -static void -gc_consumer_delete(struct gc_consumer *consumer) -{ - TRASH(consumer); - free(consumer); -} - void gc_init(void) { @@ -114,7 +89,7 @@ gc_free(void) struct gc_consumer *next = gc_tree_next(&gc.consumers, consumer); gc_tree_remove(&gc.consumers, consumer); - gc_consumer_delete(consumer); + free(consumer); consumer = next; } } @@ -213,9 +188,18 @@ struct gc_consumer * gc_consumer_register(const char *name, const struct vclock *vclock, enum gc_consumer_type type) { - struct gc_consumer *consumer = gc_consumer_new(name, vclock, type); - if (consumer != NULL) - gc_tree_insert(&gc.consumers, consumer); + struct gc_consumer *consumer = calloc(1, sizeof(*consumer)); + if (consumer == NULL) { + diag_set(OutOfMemory, sizeof(*consumer), + "malloc", "struct gc_consumer"); + return NULL; + } + + snprintf(consumer->name, GC_NAME_MAX, "%s", name); + vclock_copy(&consumer->vclock, vclock); + consumer->type = type; + + gc_tree_insert(&gc.consumers, consumer); return consumer; } @@ -225,7 +209,7 @@ gc_consumer_unregister(struct gc_consumer *consumer) int64_t signature = vclock_sum(&consumer->vclock); gc_tree_remove(&gc.consumers, consumer); - gc_consumer_delete(consumer); + free(consumer); /* * Rerun garbage collection after removing the consumer -- 2.11.0