From 13d8036992cf2ab26e68508d7d2f9bf04ecf4ad6 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 1 Aug 2018 17:11:22 -0400 Subject: [PATCH] lib: make bt_field_is_*() and bt_field_type_is_*() static inline Signed-off-by: Philippe Proulx --- include/babeltrace/ctf-ir/field-types.h | 59 ++++++++++++++++++------- include/babeltrace/ctf-ir/fields.h | 51 +++++++++++++++++---- lib/ctf-ir/field-types.c | 40 ----------------- lib/ctf-ir/fields.c | 40 ----------------- 4 files changed, 86 insertions(+), 104 deletions(-) diff --git a/include/babeltrace/ctf-ir/field-types.h b/include/babeltrace/ctf-ir/field-types.h index 13d9b6b4..951fb48b 100644 --- a/include/babeltrace/ctf-ir/field-types.h +++ b/include/babeltrace/ctf-ir/field-types.h @@ -323,8 +323,12 @@ extern enum bt_field_type_id bt_field_type_get_type_id( @sa bt_field_type_get_type_id(): Returns the type ID of a given field type. */ -extern bt_bool bt_field_type_is_integer( - struct bt_field_type *field_type); +static inline +bt_bool bt_field_type_is_integer(struct bt_field_type *field_type) +{ + return bt_field_type_get_type_id(field_type) == + BT_FIELD_TYPE_ID_INTEGER; +} /** @brief Returns whether or not the @ft \p field_type is a @floatft. @@ -340,8 +344,11 @@ extern bt_bool bt_field_type_is_integer( @sa bt_field_type_get_type_id(): Returns the type ID of a given field type. */ -extern bt_bool bt_field_type_is_floating_point( - struct bt_field_type *field_type); +static inline +bt_bool bt_field_type_is_floating_point(struct bt_field_type *field_type) +{ + return bt_field_type_get_type_id(field_type) == BT_FIELD_TYPE_ID_FLOAT; +} /** @brief Returns whether or not the @ft \p field_type is a @enumft. @@ -356,8 +363,11 @@ extern bt_bool bt_field_type_is_floating_point( @sa bt_field_type_get_type_id(): Returns the type ID of a given field type. */ -extern bt_bool bt_field_type_is_enumeration( - struct bt_field_type *field_type); +static inline +bt_bool bt_field_type_is_enumeration(struct bt_field_type *field_type) +{ + return bt_field_type_get_type_id(field_type) == BT_FIELD_TYPE_ID_ENUM; +} /** @brief Returns whether or not the @ft \p field_type is a @stringft. @@ -372,8 +382,11 @@ extern bt_bool bt_field_type_is_enumeration( @sa bt_field_type_get_type_id(): Returns the type ID of a given field type. */ -extern bt_bool bt_field_type_is_string( - struct bt_field_type *field_type); +static inline +bt_bool bt_field_type_is_string(struct bt_field_type *field_type) +{ + return bt_field_type_get_type_id(field_type) == BT_FIELD_TYPE_ID_STRING; +} /** @brief Returns whether or not the @ft \p field_type is a @structft. @@ -388,8 +401,11 @@ extern bt_bool bt_field_type_is_string( @sa bt_field_type_get_type_id(): Returns the type ID of a given field type. */ -extern bt_bool bt_field_type_is_structure( - struct bt_field_type *field_type); +static inline +bt_bool bt_field_type_is_structure(struct bt_field_type *field_type) +{ + return bt_field_type_get_type_id(field_type) == BT_FIELD_TYPE_ID_STRUCT; +} /** @brief Returns whether or not the @ft \p field_type is a @arrayft. @@ -404,8 +420,11 @@ extern bt_bool bt_field_type_is_structure( @sa bt_field_type_get_type_id(): Returns the type ID of a given field type. */ -extern bt_bool bt_field_type_is_array( - struct bt_field_type *field_type); +static inline +bt_bool bt_field_type_is_array(struct bt_field_type *field_type) +{ + return bt_field_type_get_type_id(field_type) == BT_FIELD_TYPE_ID_ARRAY; +} /** @brief Returns whether or not the @ft \p field_type is a @seqft. @@ -420,8 +439,12 @@ extern bt_bool bt_field_type_is_array( @sa bt_field_type_get_type_id(): Returns the type ID of a given field type. */ -extern bt_bool bt_field_type_is_sequence( - struct bt_field_type *field_type); +static inline +bt_bool bt_field_type_is_sequence(struct bt_field_type *field_type) +{ + return bt_field_type_get_type_id(field_type) == + BT_FIELD_TYPE_ID_SEQUENCE; +} /** @brief Returns whether or not the @ft \p field_type is a @varft. @@ -436,8 +459,12 @@ extern bt_bool bt_field_type_is_sequence( @sa bt_field_type_get_type_id(): Returns the type ID of a given field type. */ -extern bt_bool bt_field_type_is_variant( - struct bt_field_type *field_type); +static inline +bt_bool bt_field_type_is_variant(struct bt_field_type *field_type) +{ + return bt_field_type_get_type_id(field_type) == + BT_FIELD_TYPE_ID_VARIANT; +} /** @} */ diff --git a/include/babeltrace/ctf-ir/fields.h b/include/babeltrace/ctf-ir/fields.h index 7d811c96..f975e530 100644 --- a/include/babeltrace/ctf-ir/fields.h +++ b/include/babeltrace/ctf-ir/fields.h @@ -39,6 +39,9 @@ /* For bt_bool */ #include +/* For BT_FIELD_TYPE_ID_* */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -219,7 +222,11 @@ extern enum bt_field_type_id bt_field_get_type_id(struct bt_field *field); @sa bt_field_get_type_id(): Returns the type ID of a given field's type. */ -extern bt_bool bt_field_is_integer(struct bt_field *field); +static inline +bt_bool bt_field_is_integer(struct bt_field *field) +{ + return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_INTEGER; +} /** @brief Returns whether or not the @field \p field is a @floatfield. @@ -235,7 +242,11 @@ extern bt_bool bt_field_is_integer(struct bt_field *field); @sa bt_field_get_type_id(): Returns the type ID of a given field's type. */ -extern bt_bool bt_field_is_floating_point(struct bt_field *field); +static inline +bt_bool bt_field_is_floating_point(struct bt_field *field) +{ + return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_FLOAT; +} /** @brief Returns whether or not the @field \p field is a @enumfield. @@ -251,7 +262,11 @@ extern bt_bool bt_field_is_floating_point(struct bt_field *field); @sa bt_field_get_type_id(): Returns the type ID of a given field's type. */ -extern bt_bool bt_field_is_enumeration(struct bt_field *field); +static inline +bt_bool bt_field_is_enumeration(struct bt_field *field) +{ + return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_ENUM; +} /** @brief Returns whether or not the @field \p field is a @stringfield. @@ -267,7 +282,11 @@ extern bt_bool bt_field_is_enumeration(struct bt_field *field); @sa bt_field_get_type_id(): Returns the type ID of a given field's type. */ -extern bt_bool bt_field_is_string(struct bt_field *field); +static inline +bt_bool bt_field_is_string(struct bt_field *field) +{ + return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_STRING; +} /** @brief Returns whether or not the @field \p field is a @structfield. @@ -283,7 +302,11 @@ extern bt_bool bt_field_is_string(struct bt_field *field); @sa bt_field_get_type_id(): Returns the type ID of a given field's type. */ -extern bt_bool bt_field_is_structure(struct bt_field *field); +static inline +bt_bool bt_field_is_structure(struct bt_field *field) +{ + return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_STRUCT; +} /** @brief Returns whether or not the @field \p field is a @arrayfield. @@ -299,7 +322,11 @@ extern bt_bool bt_field_is_structure(struct bt_field *field); @sa bt_field_get_type_id(): Returns the type ID of a given field's type. */ -extern bt_bool bt_field_is_array(struct bt_field *field); +static inline +bt_bool bt_field_is_array(struct bt_field *field) +{ + return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_ARRAY; +} /** @brief Returns whether or not the @field \p field is a @seqfield. @@ -315,7 +342,11 @@ extern bt_bool bt_field_is_array(struct bt_field *field); @sa bt_field_get_type_id(): Returns the type ID of a given field's type. */ -extern bt_bool bt_field_is_sequence(struct bt_field *field); +static inline +bt_bool bt_field_is_sequence(struct bt_field *field) +{ + return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_SEQUENCE; +} /** @brief Returns whether or not the @field \p field is a @varfield. @@ -331,7 +362,11 @@ extern bt_bool bt_field_is_sequence(struct bt_field *field); @sa bt_field_get_type_id(): Returns the type ID of a given field's type. */ -extern bt_bool bt_field_is_variant(struct bt_field *field); +static inline +bt_bool bt_field_is_variant(struct bt_field *field) +{ + return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_VARIANT; +} /** @} */ diff --git a/lib/ctf-ir/field-types.c b/lib/ctf-ir/field-types.c index c880d306..4e808b93 100644 --- a/lib/ctf-ir/field-types.c +++ b/lib/ctf-ir/field-types.c @@ -3390,46 +3390,6 @@ enum bt_field_type_id bt_field_type_get_type_id(struct bt_field_type *ft) return bt_field_type_common_get_type_id((void *) ft); } -int bt_field_type_is_integer(struct bt_field_type *type) -{ - return bt_field_type_get_type_id(type) == BT_FIELD_TYPE_ID_INTEGER; -} - -int bt_field_type_is_floating_point(struct bt_field_type *type) -{ - return bt_field_type_get_type_id(type) == BT_FIELD_TYPE_ID_FLOAT; -} - -int bt_field_type_is_enumeration(struct bt_field_type *type) -{ - return bt_field_type_get_type_id(type) == BT_FIELD_TYPE_ID_ENUM; -} - -int bt_field_type_is_string(struct bt_field_type *type) -{ - return bt_field_type_get_type_id(type) == BT_FIELD_TYPE_ID_STRING; -} - -int bt_field_type_is_structure(struct bt_field_type *type) -{ - return bt_field_type_get_type_id(type) == BT_FIELD_TYPE_ID_STRUCT; -} - -int bt_field_type_is_array(struct bt_field_type *type) -{ - return bt_field_type_get_type_id(type) == BT_FIELD_TYPE_ID_ARRAY; -} - -int bt_field_type_is_sequence(struct bt_field_type *type) -{ - return bt_field_type_get_type_id(type) == BT_FIELD_TYPE_ID_SEQUENCE; -} - -int bt_field_type_is_variant(struct bt_field_type *type) -{ - return bt_field_type_get_type_id(type) == BT_FIELD_TYPE_ID_VARIANT; -} - BT_HIDDEN void bt_field_type_common_freeze(struct bt_field_type_common *ft) { diff --git a/lib/ctf-ir/fields.c b/lib/ctf-ir/fields.c index 3a0e063b..7ed1d738 100644 --- a/lib/ctf-ir/fields.c +++ b/lib/ctf-ir/fields.c @@ -217,46 +217,6 @@ enum bt_field_type_id bt_field_get_type_id(struct bt_field *field) return field_common->type->id; } -bt_bool bt_field_is_integer(struct bt_field *field) -{ - return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_INTEGER; -} - -bt_bool bt_field_is_floating_point(struct bt_field *field) -{ - return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_FLOAT; -} - -bt_bool bt_field_is_enumeration(struct bt_field *field) -{ - return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_ENUM; -} - -bt_bool bt_field_is_string(struct bt_field *field) -{ - return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_STRING; -} - -bt_bool bt_field_is_structure(struct bt_field *field) -{ - return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_STRUCT; -} - -bt_bool bt_field_is_array(struct bt_field *field) -{ - return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_ARRAY; -} - -bt_bool bt_field_is_sequence(struct bt_field *field) -{ - return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_SEQUENCE; -} - -bt_bool bt_field_is_variant(struct bt_field *field) -{ - return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_VARIANT; -} - int64_t bt_field_sequence_get_length(struct bt_field *field) { return bt_field_common_sequence_get_length((void *) field); -- 2.34.1