Re: Function completion for GVariant maybe types?



Is it possible to determine the child data type without retrieving
the complete value?

See above.

How do you think about the following update suggestion?


diff --git a/glib/gvariant.c b/glib/gvariant.c
index c3d1947..9c107dd 100644
--- a/glib/gvariant.c
+++ b/glib/gvariant.c
@@ -682,6 +682,27 @@ g_variant_new_maybe (const GVariantType *child_type,
   return value;
 }

+GVariant *
+g_variant_new_nothing_from_type (GVariant const * value)
+{
+  if (value == NULL)
+ 	return g_variant_new ("ms", NULL);
+  else
+    {
+	  GVariantType* type = g_variant_get_type (value);
+
+      if (g_variant_type_is_maybe (type))
+        {
+		  GVariant* contained = g_variant_get_child_value (value, 0);
+		  type = g_variant_get_type (contained);
+		  g_variant_unref(contained);
+		  return g_variant_new_maybe (type, NULL);
+        }
+      else
+ 		  return g_variant_new_maybe (type, value);
+    }
+}
+
 /**
  * g_variant_get_maybe:
  * @value: a maybe-typed value
diff --git a/glib/gvariant.h b/glib/gvariant.h
index 9abcc0b..50877f2 100644
--- a/glib/gvariant.h
+++ b/glib/gvariant.h
@@ -128,6 +128,7 @@ gchar ** g_variant_dup_bytestring_array (GVarian

GVariant * g_variant_new_maybe (const GVariantType *child_type,

GVariant             *child);
+GVariant * g_variant_new_nothing_from_type (GVariant const * value); GVariant * g_variant_new_array (const GVariantType *child_type,

GVariant * const     *children,
gsize n_children);



The usual answer to "should we optimise $THING?" applies:
if you don't have profiling data that indicates that $THING is a bottleneck,
then no, optimising $THING isn't useful.

Would it be more efficient to query only a data type instead of copying a potential big data structure?

Regards,
Markus


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]