structural refactoring for less layers of if-else nesting
@@ -22,7 +22,8 @@ void _cbor_builder_append(cbor_item_t *item,
if (ctx->stack->size == 0) {
/* Top level item */
ctx->root = item;
- } else {
+ return;
+ }
/* Part of a bigger structure */
switch (ctx->stack->top->item->type) {
case CBOR_TYPE_ARRAY: {
@@ -37,21 +38,18 @@ void _cbor_builder_append(cbor_item_t *item,
ctx->creation_failed = true;
cbor_decref(&item);
break;
- } else {
+ }
+ cbor_decref(&item);
ctx->stack->top->subitems--;
if (ctx->stack->top->subitems == 0) {
cbor_item_t *stack_item = ctx->stack->top->item;
_cbor_stack_pop(ctx->stack);
_cbor_builder_append(stack_item, ctx);
}
- }
- cbor_decref(&item);
} else {
/* Indefinite array, don't bother with subitems */
if (!cbor_array_push(ctx->stack->top->item, item)) {
ctx->creation_failed = true;
- cbor_decref(&item);
- break;
}
cbor_decref(&item);
}
@@ -104,7 +102,6 @@ void _cbor_builder_append(cbor_item_t *item,
}
}
}
-}
#define CHECK_RES(ctx, res) \
do { \
