[gjs: 8/10] arg: Refactor create_hash_table_for_key_type() to take GITypeTag
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 8/10] arg: Refactor create_hash_table_for_key_type() to take GITypeTag
- Date: Sun, 6 Mar 2022 00:46:42 +0000 (UTC)
commit 99739c5839d24d421e77d03a33724e960aefc7bb
Author: Philip Chimento <philip chimento gmail com>
Date: Sat Feb 19 16:37:42 2022 -0800
arg: Refactor create_hash_table_for_key_type() to take GITypeTag
This function doesn't need the whole GITypeInfo, just the type tag. This
refactor allows reusing it in a separate code path for basic types that
are only identified by their type tag.
gi/arg.cpp | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 12ecb5346..77e6af418 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -336,13 +336,10 @@ GJS_JSAPI_RETURN_CONVENTION static bool gjs_array_to_g_list(
}
[[nodiscard]] static GHashTable* create_hash_table_for_key_type(
- GITypeInfo* key_param_info) {
+ GITypeTag key_type) {
/* 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. */
-
- GITypeTag key_type = g_type_info_get_tag(key_param_info);
-
if (key_type == GI_TYPE_TAG_UTF8 || key_type == GI_TYPE_TAG_FILENAME)
return g_hash_table_new(g_str_hash, g_str_equal);
return g_hash_table_new(NULL, NULL);
@@ -529,8 +526,9 @@ static bool gjs_object_to_g_hash(JSContext* context, JS::HandleObject props,
if (!JS_Enumerate(context, props, &ids))
return false;
+ GITypeTag key_tag = g_type_info_get_tag(key_param_info);
GjsAutoPointer<GHashTable, GHashTable, g_hash_table_destroy> result =
- create_hash_table_for_key_type(key_param_info);
+ create_hash_table_for_key_type(key_tag);
JS::RootedValue key_js(context), val_js(context);
JS::RootedId cur_id(context);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]