[gjs: 2/7] arg: Add is_string_type() helper function
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 2/7] arg: Add is_string_type() helper function
- Date: Sun, 22 May 2022 05:49:02 +0000 (UTC)
commit 8160e48bf5ad374f406462b715fabff2f392a0ac
Author: Philip Chimento <philip chimento gmail com>
Date: Sat Feb 19 16:35:51 2022 -0800
arg: Add is_string_type() helper function
This increases expressiveness of the code because it expresses the
intent better than comparing the different values of the GITypeTag. This
will be used more in future refactors.
gi/arg.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index d2c1149ed..d7f294cc0 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -209,6 +209,10 @@ static bool _gjs_enum_value_is_valid(JSContext* context, GIEnumInfo* enum_info,
}
}
+[[nodiscard]] static inline bool is_string_type(GITypeTag tag) {
+ return tag == GI_TYPE_TAG_FILENAME || tag == GI_TYPE_TAG_UTF8;
+}
+
/* Check if an argument of the given needs to be released if we obtained it
* from out argument (or the return value), and we're transferring ownership
*/
@@ -340,7 +344,7 @@ GJS_JSAPI_RETURN_CONVENTION static bool gjs_array_to_g_list(
/* Don't use key/value destructor functions here, because we can't
* construct correct ones in general if the value type is complex.
* Rely on the type-aware g_argument_release functions. */
- if (key_type == GI_TYPE_TAG_UTF8 || key_type == GI_TYPE_TAG_FILENAME)
+ if (is_string_type(key_type))
return g_hash_table_new(g_str_hash, g_str_equal);
return g_hash_table_new(NULL, NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]