ctf plugin: BTR: use "borrow" functions where possible
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 17 Apr 2018 02:58:11 +0000 (22:58 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 2 May 2019 04:05:45 +0000 (00:05 -0400)
Use "borrow" API functions when possible to avoid useless reference
count changes.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
plugins/ctf/common/btr/btr.c
plugins/ctf/common/btr/btr.h
plugins/ctf/common/notif-iter/notif-iter.c

index 7ccfab0e64ab3d988c686c289f44414150cdc6f2..2f0f13f1dc1196cca8a9b77609d18a7c531ed30e 100644 (file)
@@ -181,7 +181,6 @@ void stack_entry_free_func(gpointer data)
 {
        struct stack_entry *entry = data;
 
-       BT_PUT(entry->base_type);
        g_free(entry);
 }
 
@@ -266,7 +265,6 @@ int stack_push(struct stack *stack, struct bt_field_type *base_type,
 
        BT_ASSERT(stack);
        BT_ASSERT(base_type);
-
        BT_LOGV("Pushing field type on stack: stack-addr=%p, "
                "ft-addr=%p, ft-id=%s, base-length=%zu, "
                "stack-size-before=%u, stack-size-after=%u",
@@ -282,7 +280,6 @@ int stack_push(struct stack *stack, struct bt_field_type *base_type,
        }
 
        entry->base_type = base_type;
-       bt_get(entry->base_type);
        entry->base_len = base_len;
        g_ptr_array_add(stack->entries, entry);
 
@@ -316,7 +313,6 @@ static inline
 unsigned int stack_size(struct stack *stack)
 {
        BT_ASSERT(stack);
-
        return stack->entries->len;
 }
 
@@ -438,11 +434,11 @@ int get_basic_field_type_size(struct bt_btr *btr,
        {
                struct bt_field_type *int_type;
 
-               int_type = bt_field_type_enumeration_get_container_field_type(
-                       field_type);
+               int_type =
+                       bt_field_type_enumeration_borrow_container_field_type(
+                               field_type);
                BT_ASSERT(int_type);
                size = get_basic_field_type_size(btr, int_type);
-               BT_PUT(int_type);
                break;
        }
        default:
@@ -471,7 +467,7 @@ void stitch_append_from_buf(struct bt_btr *btr, size_t sz)
 {
        size_t stitch_byte_at;
        size_t buf_byte_at;
-       size_t nb_bytes;;
+       size_t nb_bytes;
 
        if (sz == 0) {
                return;
@@ -796,12 +792,11 @@ enum bt_btr_status read_basic_enum_and_call_cb(struct bt_btr *btr,
        struct bt_field_type *int_field_type;
        enum bt_btr_status status = BT_BTR_STATUS_OK;
 
-       int_field_type = bt_field_type_enumeration_get_container_field_type(
+       int_field_type = bt_field_type_enumeration_borrow_container_field_type(
                btr->cur_basic_field_type);
        BT_ASSERT(int_field_type);
        status = read_basic_int_and_call(btr, buf, at,
                int_field_type, btr->cur_basic_field_type);
-       bt_put(int_field_type);
        return status;
 }
 
@@ -1285,7 +1280,7 @@ enum bt_btr_status next_field_state(struct bt_btr *btr)
        /* Get next field's type */
        switch (bt_field_type_get_type_id(top->base_type)) {
        case BT_FIELD_TYPE_ID_STRUCT:
-               ret = bt_field_type_structure_get_field_by_index(
+               ret = bt_field_type_structure_borrow_field_by_index(
                        top->base_type, NULL, &next_field_type,
                        top->index);
                if (ret) {
@@ -1294,18 +1289,18 @@ enum bt_btr_status next_field_state(struct bt_btr *btr)
                break;
        case BT_FIELD_TYPE_ID_ARRAY:
                next_field_type =
-                       bt_field_type_array_get_element_field_type(
+                       bt_field_type_array_borrow_element_field_type(
                                top->base_type);
                break;
        case BT_FIELD_TYPE_ID_SEQUENCE:
                next_field_type =
-                       bt_field_type_sequence_get_element_field_type(
+                       bt_field_type_sequence_borrow_element_field_type(
                                top->base_type);
                break;
        case BT_FIELD_TYPE_ID_VARIANT:
                /* Variant types are dynamic: query the user, he should know! */
                next_field_type =
-                       btr->user.cbs.query.get_variant_type(
+                       btr->user.cbs.query.borrow_variant_field_type(
                                top->base_type, btr->user.data);
                break;
        default:
@@ -1353,15 +1348,13 @@ enum bt_btr_status next_field_state(struct bt_btr *btr)
                        "btr-addr=%p, cur-basic-ft-addr=%p, "
                        "next-basic-ft-addr=%p",
                        btr, btr->cur_basic_field_type, next_field_type);
-               BT_MOVE(btr->cur_basic_field_type, next_field_type);
+               btr->cur_basic_field_type = next_field_type;
 
                /* Next state: align a basic type */
                btr->state = BTR_STATE_ALIGN_BASIC;
        }
 
 end:
-       BT_PUT(next_field_type);
-
        return status;
 }
 
@@ -1435,7 +1428,6 @@ void bt_btr_destroy(struct bt_btr *btr)
        }
 
        BT_LOGD("Destroying BTR: addr=%p", btr);
-       BT_PUT(btr->cur_basic_field_type);
        g_free(btr);
 }
 
@@ -1444,7 +1436,6 @@ void reset(struct bt_btr *btr)
 {
        BT_LOGD("Resetting BTR: addr=%p", btr);
        stack_clear(btr->stack);
-       BT_PUT(btr->cur_basic_field_type);
        stitch_reset(btr);
        btr->buf.addr = NULL;
        btr->last_bo = BT_BYTE_ORDER_UNKNOWN;
@@ -1510,7 +1501,6 @@ size_t bt_btr_start(struct bt_btr *btr,
        } else {
                /* Basic type: set as current basic type */
                btr->cur_basic_field_type = type;
-               bt_get(btr->cur_basic_field_type);
                btr->state = BTR_STATE_ALIGN_BASIC;
        }
 
index 55d95912dfb04bde929a7d113252a306a16a4296..c4f400911159059b8b12b70268d5879acba02480 100644 (file)
@@ -265,7 +265,7 @@ struct bt_btr_cbs {
                 * @returns             Current selected type (owned by
                 *                      this) or \c NULL on error
                 */
-               struct bt_field_type * (* get_variant_type)(
+               struct bt_field_type * (* borrow_variant_field_type)(
                                struct bt_field_type *type, void *data);
        } query;
 };
index 642f9931cb2bf48e22562f4e4d1940a9974b26c7..bf3f9a743f1b8030b400690ca08ce35cfc2609a6 100644 (file)
@@ -2497,7 +2497,7 @@ end:
 }
 
 static
-struct bt_field_type *btr_get_variant_type_cb(
+struct bt_field_type *btr_borrow_variant_field_type_cb(
                struct bt_field_type *type, void *data)
 {
        struct bt_field_path *path;
@@ -2538,13 +2538,12 @@ struct bt_field_type *btr_get_variant_type_cb(
                goto end;
        }
 
-       selected_field_type = bt_field_get_type(selected_field);
+       selected_field_type = bt_field_borrow_type(selected_field);
 
 end:
        BT_PUT(tag_field);
        BT_PUT(selected_field);
        BT_PUT(path);
-
        return selected_field_type;
 }
 
@@ -3065,7 +3064,7 @@ struct bt_notif_iter *bt_notif_iter_create(struct bt_trace *trace,
                },
                .query = {
                        .get_sequence_length = btr_get_sequence_length_cb,
-                       .get_variant_type = btr_get_variant_type_cb,
+                       .borrow_variant_field_type = btr_borrow_variant_field_type_cb,
                },
        };
 
This page took 0.028639 seconds and 4 git commands to generate.