From fcd202650666c2487153d03e35d543ea05be2c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 24 Aug 2020 13:48:24 +0200 Subject: [PATCH] gitypelib-internal: Use a switch to check if blob is a registered type No need to go through all the possible blob types, while we can use an inline function to check it. Use an attribute to ensure the function will be inlined, when this is not available just fallback to the previous definition --- gitypelib-internal.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/gitypelib-internal.h b/gitypelib-internal.h index 494ab2b37..4ba53a2a5 100644 --- a/gitypelib-internal.h +++ b/gitypelib-internal.h @@ -185,6 +185,32 @@ typedef enum { BLOB_TYPE_UNION } GTypelibBlobType; + +#if defined (G_CAN_INLINE) && defined (G_ALWAYS_INLINE) + +G_ALWAYS_INLINE +inline gboolean +_blob_is_registered_type (GTypelibBlobType blob_type) +{ + switch (blob_type) + { + case BLOB_TYPE_STRUCT: + case BLOB_TYPE_UNION: + case BLOB_TYPE_ENUM: + case BLOB_TYPE_FLAGS: + case BLOB_TYPE_OBJECT: + case BLOB_TYPE_INTERFACE: + return TRUE; + default: + return FALSE; + } +} + +#define BLOB_IS_REGISTERED_TYPE(blob) \ + _blob_is_registered_type ((GTypelibBlobType) (blob)->blob_type) + +#else + #define BLOB_IS_REGISTERED_TYPE(blob) \ ((blob)->blob_type == BLOB_TYPE_STRUCT || \ (blob)->blob_type == BLOB_TYPE_UNION || \ @@ -193,6 +219,8 @@ typedef enum { (blob)->blob_type == BLOB_TYPE_OBJECT || \ (blob)->blob_type == BLOB_TYPE_INTERFACE) +#endif /* defined (G_CAN_INLINE) && defined (G_ALWAYS_INLINE) */ + /** * Header: * @magic: See #G_IR_MAGIC.