From 2829190c6db1463f7f8b71db147a765ebe6455ed Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 2 Apr 2015 17:40:21 -0400 Subject: [PATCH] Fix: ir: return current variant's field if possible MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/event-fields.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/formats/ctf/ir/event-fields.c b/formats/ctf/ir/event-fields.c index 55316f49..6220144a 100644 --- a/formats/ctf/ir/event-fields.c +++ b/formats/ctf/ir/event-fields.c @@ -601,6 +601,31 @@ struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *field, } tag_enum_value = tag_enum_integer->definition.value._signed; + + /* + * If the variant currently has a tag and a payload, and if the + * requested tag value is the same as the current one, return + * the current payload instead of creating a fresh one. + */ + if (variant->tag && variant->payload) { + struct bt_ctf_field *cur_tag_container = NULL; + struct bt_ctf_field_integer *cur_tag_enum_integer; + int64_t cur_tag_value; + + cur_tag_container = + bt_ctf_field_enumeration_get_container(variant->tag); + cur_tag_enum_integer = container_of(cur_tag_container, + struct bt_ctf_field_integer, parent); + bt_ctf_field_put(cur_tag_container); + cur_tag_value = cur_tag_enum_integer->definition.value._signed; + + if (cur_tag_value == tag_enum_value) { + new_field = variant->payload; + bt_ctf_field_get(new_field); + goto end; + } + } + field_type = bt_ctf_field_type_variant_get_field_type_signed( variant_type, tag_enum_value); if (!field_type) { -- 2.34.1