From b116c4f79d601e22b8634ad0f6052e4f3bf07d97 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 20 Apr 2015 10:07:36 -0700 Subject: [PATCH] Remove expensive asserts from NDEBUG builds --- src/core/transport/stream_op.c | 6 ++++++ src/core/transport/stream_op.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/core/transport/stream_op.c b/src/core/transport/stream_op.c index f3e634d8532..ed31ec59a15 100644 --- a/src/core/transport/stream_op.c +++ b/src/core/transport/stream_op.c @@ -92,12 +92,14 @@ void grpc_stream_ops_unref_owned_objects(grpc_stream_op *ops, size_t nops) { } static void assert_contained_metadata_ok(grpc_stream_op *ops, size_t nops) { +#ifndef NDEBUG size_t i; for (i = 0; i < nops; i++) { if (ops[i].type == GRPC_OP_METADATA) { grpc_metadata_batch_assert_ok(&ops[i].data.metadata); } } +#endif } static void expandto(grpc_stream_op_buffer *sopb, size_t new_capacity) { @@ -183,6 +185,7 @@ void grpc_sopb_append(grpc_stream_op_buffer *sopb, grpc_stream_op *ops, } static void assert_valid_list(grpc_mdelem_list *list) { +#ifndef NDEBUG grpc_linked_mdelem *l; GPR_ASSERT((list->head == NULL) == (list->tail == NULL)); @@ -198,12 +201,15 @@ static void assert_valid_list(grpc_mdelem_list *list) { if (l->next) GPR_ASSERT(l->next->prev == l); if (l->prev) GPR_ASSERT(l->prev->next == l); } +#endif } +#ifndef NDEBUG void grpc_metadata_batch_assert_ok(grpc_metadata_batch *comd) { assert_valid_list(&comd->list); assert_valid_list(&comd->garbage); } +#endif void grpc_metadata_batch_init(grpc_metadata_batch *comd) { comd->list.head = comd->list.tail = comd->garbage.head = comd->garbage.tail = diff --git a/src/core/transport/stream_op.h b/src/core/transport/stream_op.h index f6ce140bd80..20146b9af21 100644 --- a/src/core/transport/stream_op.h +++ b/src/core/transport/stream_op.h @@ -113,7 +113,11 @@ void grpc_metadata_batch_filter(grpc_metadata_batch *comd, grpc_mdelem *elem), void *user_data); +#ifndef NDEBUG void grpc_metadata_batch_assert_ok(grpc_metadata_batch *comd); +#else +#define grpc_metadata_batch_assert_ok(comd) do {} while (0) +#endif /* Represents a single operation performed on a stream/transport */ typedef struct grpc_stream_op {