[gnome-network-displays/cc-tmp: 44/80] json: for loop and assert changes
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-network-displays/cc-tmp: 44/80] json: for loop and assert changes
- Date: Fri, 9 Sep 2022 12:03:50 +0000 (UTC)
commit 06f571a2335b12bb3a77f029f4814f09f4fe4a24
Author: Anupam Kumar <kyteinsky gmail com>
Date: Sat Sep 3 18:00:37 2022 +0530
json: for loop and assert changes
src/cc/cc-json-helper.c | 34 ++++++++++------------------------
1 file changed, 10 insertions(+), 24 deletions(-)
---
diff --git a/src/cc/cc-json-helper.c b/src/cc/cc-json-helper.c
index 16c3738..c19a6d1 100644
--- a/src/cc/cc-json-helper.c
+++ b/src/cc/cc-json-helper.c
@@ -23,47 +23,35 @@ cc_json_helper_build_internal (JsonBuilder *builder,
gchar *first_key,
va_list var_args)
{
- gchar *key = first_key;
-
- while (key)
+ for (gchar *key = first_key; key != NULL; key = va_arg (var_args, gchar *))
{
json_builder_set_member_name (builder, key);
CcJsonType type = va_arg (var_args, CcJsonType);
- if (type < CC_JSON_TYPE_STRING || type > CC_JSON_TYPE_ARRAY_OBJECT)
- {
- g_warning ("CcJsonHelper: Incorrect type passed in json contructor: %d", type);
- return;
- }
+ g_assert (type >= CC_JSON_TYPE_STRING && type <= CC_JSON_TYPE_ARRAY_OBJECT);
switch (type)
{
case CC_JSON_TYPE_STRING:
json_builder_add_string_value (builder, va_arg (var_args, gchar *));
- break;
+ continue;
case CC_JSON_TYPE_INT:
json_builder_add_int_value (builder, va_arg (var_args, gint));
- break;
+ continue;
case CC_JSON_TYPE_DOUBLE:
json_builder_add_double_value (builder, va_arg (var_args, gdouble));
- break;
+ continue;
case CC_JSON_TYPE_BOOLEAN:
json_builder_add_boolean_value (builder, va_arg (var_args, gboolean));
- break;
+ continue;
case CC_JSON_TYPE_NULL: /* no additional arg is required here */
json_builder_add_null_value (builder);
- break;
+ continue;
case CC_JSON_TYPE_OBJECT:
json_builder_add_value (builder, va_arg (var_args, JsonNode *));
- break;
- default:
- break;
- }
-
- if (type < CC_JSON_TYPE_ARRAY_STRING)
- {
- key = va_arg (var_args, gchar *);
continue;
+ default:
+ return;
}
json_builder_begin_array (builder);
@@ -93,13 +81,11 @@ cc_json_helper_build_internal (JsonBuilder *builder,
json_builder_add_value (builder, g_array_index (arr, JsonNode *, i));
break;
default:
- break;
+ return;
}
}
json_builder_end_array (builder);
-
- key = va_arg (var_args, gchar *);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]