[libvirt-glib 3/3] Remove the _glib xml helpers

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

 



The reason for them being there was that they were more expensive
than the helpers returning an xmlChar* (additional g_strdup). Now
that we are returning a pointer to const data inside the xml node,
the _glib helpers only use is to cast from const xmlChar * to
const char *. Removing them makes the code simpler.
---
 libvirt-gconfig/libvirt-gconfig-domain-disk.c      |    4 +-
 libvirt-gconfig/libvirt-gconfig-domain-graphics.c  |   12 ++++----
 libvirt-gconfig/libvirt-gconfig-domain-interface.c |   16 +++++-----
 libvirt-gconfig/libvirt-gconfig-helpers-private.h  |    8 +----
 libvirt-gconfig/libvirt-gconfig-helpers.c          |   32 +++----------------
 libvirt-gconfig/libvirt-gconfig-object.c           |   16 +++++-----
 6 files changed, 31 insertions(+), 57 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
index 2944739..5d0acb5 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-disk.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
@@ -76,14 +76,14 @@ gvir_config_domain_disk_new_from_tree(GVirConfigXmlDoc *doc,
     GVirConfigObject *object;
     GVirConfigDomainDisk *disk;
     GVirConfigDomainDiskType type;
-    const xmlChar *type_str;
+    const char *type_str;
 
     type_str = gvir_config_xml_get_attribute_content(tree, "type");
     if (type_str == NULL)
         return NULL;
 
     type = gvir_config_genum_get_value(GVIR_CONFIG_TYPE_DOMAIN_DISK_TYPE,
-                                       (const char *)type_str,
+                                       type_str,
                                        GVIR_CONFIG_DOMAIN_DISK_FILE);
     if (type == -1)
         return NULL;
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics.c b/libvirt-gconfig/libvirt-gconfig-domain-graphics.c
index c79406e..9c1e980 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-graphics.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics.c
@@ -53,22 +53,22 @@ G_GNUC_INTERNAL GVirConfigDomainDevice *
 gvir_config_domain_graphics_new_from_tree(GVirConfigXmlDoc *doc,
                                           xmlNodePtr tree)
 {
-    const xmlChar *type;
+    const char *type;
     GType gtype;
 
     type = gvir_config_xml_get_attribute_content(tree, "type");
     if (type == NULL)
         return NULL;
 
-    if (xmlStrEqual(type, (xmlChar*)"sdl")) {
+    if (g_str_equal(type, "sdl")) {
         gtype = GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_SDL;
-    } else if (xmlStrEqual(type, (xmlChar*)"vnc")) {
+    } else if (g_str_equal(type, "vnc")) {
         gtype = GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_VNC;
-    } else if (xmlStrEqual(type, (xmlChar*)"spice")) {
+    } else if (g_str_equal(type, "spice")) {
         gtype = GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_SPICE;
-    } else if (xmlStrEqual(type, (xmlChar*)"rdp")) {
+    } else if (g_str_equal(type, "rdp")) {
         goto unimplemented;
-    } else if (xmlStrEqual(type, (xmlChar*)"desktop")) {
+    } else if (g_str_equal(type, "desktop")) {
         goto unimplemented;
     } else {
         g_debug("Unknown graphics node: %s", type);
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-interface.c b/libvirt-gconfig/libvirt-gconfig-domain-interface.c
index 6f539a2..2f7be5c 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-interface.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-interface.c
@@ -135,26 +135,26 @@ G_GNUC_INTERNAL GVirConfigDomainDevice *
 gvir_config_domain_interface_new_from_tree(GVirConfigXmlDoc *doc,
                                            xmlNodePtr tree)
 {
-    const xmlChar *type;
+    const char *type;
     GType gtype;
 
     type = gvir_config_xml_get_attribute_content(tree, "type");
     if (type == NULL)
         return NULL;
 
-    if (xmlStrEqual(type, (xmlChar*)"network")) {
+    if (g_str_equal(type, "network")) {
         gtype = GVIR_CONFIG_TYPE_DOMAIN_INTERFACE_NETWORK;
-    } else if (xmlStrEqual(type, (xmlChar*)"user")) {
+    } else if (g_str_equal(type, "user")) {
         gtype = GVIR_CONFIG_TYPE_DOMAIN_INTERFACE_USER;
-    } else if (xmlStrEqual(type, (xmlChar*)"bridge")) {
+    } else if (g_str_equal(type, "bridge")) {
         goto unimplemented;
-    } else if (xmlStrEqual(type, (xmlChar*)"direct")) {
+    } else if (g_str_equal(type, "direct")) {
         goto unimplemented;
-    } else if (xmlStrEqual(type, (xmlChar*)"server")) {
+    } else if (g_str_equal(type, "server")) {
         goto unimplemented;
-    } else if (xmlStrEqual(type, (xmlChar*)"mcast")) {
+    } else if (g_str_equal(type, "mcast")) {
         goto unimplemented;
-    } else if (xmlStrEqual(type, (xmlChar*)"ethernet")) {
+    } else if (g_str_equal(type, "ethernet")) {
         goto unimplemented;
     } else {
         g_debug("Unknown domain interface node: %s", type);
diff --git a/libvirt-gconfig/libvirt-gconfig-helpers-private.h b/libvirt-gconfig/libvirt-gconfig-helpers-private.h
index aa53874..dbf70a3 100644
--- a/libvirt-gconfig/libvirt-gconfig-helpers-private.h
+++ b/libvirt-gconfig/libvirt-gconfig-helpers-private.h
@@ -50,15 +50,11 @@ void gvir_config_xml_foreach_child(xmlNodePtr node,
                                    GVirConfigXmlNodeIterator iter_func,
                                    gpointer opaque);
 xmlNode * gvir_config_xml_get_element (xmlNode *node, ...);
-const xmlChar * gvir_config_xml_get_child_element_content (xmlNode *node,
+const char * gvir_config_xml_get_child_element_content (xmlNode *node,
                                                            const char *child_name);
-const char *gvir_config_xml_get_child_element_content_glib (xmlNode *node,
-                                                            const char *child_name);
-const xmlChar *gvir_config_xml_get_attribute_content(xmlNodePtr node,
+const char *gvir_config_xml_get_attribute_content(xmlNodePtr node,
                                                      const char *attr_name);
 char *gvir_config_xml_node_to_string(xmlNodePtr node);
-const char *gvir_config_xml_get_attribute_content_glib(xmlNodePtr node,
-                                                       const char *attr_name);
 const char *gvir_config_genum_get_nick (GType enum_type, gint value);
 int gvir_config_genum_get_value (GType enum_type, const char *nick, gint default_value);
 G_END_DECLS
diff --git a/libvirt-gconfig/libvirt-gconfig-helpers.c b/libvirt-gconfig/libvirt-gconfig-helpers.c
index ba54590..87b1375 100644
--- a/libvirt-gconfig/libvirt-gconfig-helpers.c
+++ b/libvirt-gconfig/libvirt-gconfig-helpers.c
@@ -186,8 +186,7 @@ void gvir_config_xml_foreach_child(xmlNodePtr node,
 }
 
 /*
- * gvir_config_xml_get_element, gvir_config_xml_get_child_element_content
- * and gvir_config_xml_get_child_element_content_glib are:
+ * gvir_config_xml_get_element is
  *
  * Copyright (C) 2006, 2007 OpenedHand Ltd.
  *
@@ -220,7 +219,7 @@ gvir_config_xml_get_element (xmlNode *node, ...)
         return node;
 }
 
-const xmlChar *
+G_GNUC_INTERNAL const char *
 gvir_config_xml_get_child_element_content (xmlNode *node,
                                            const char *child_name)
 {
@@ -230,42 +229,21 @@ gvir_config_xml_get_child_element_content (xmlNode *node,
     if (!child_node || !(child_node->children))
         return NULL;
 
-    return child_node->children->content;
+    return (const char *)child_node->children->content;
 }
 
-const char *
-gvir_config_xml_get_child_element_content_glib (xmlNode *node,
-                                                const char *child_name)
-{
-    const xmlChar *content;
-
-    content = gvir_config_xml_get_child_element_content(node, child_name);
-
-    return (const char *)content;
-}
-
-G_GNUC_INTERNAL const xmlChar *
+G_GNUC_INTERNAL const char *
 gvir_config_xml_get_attribute_content(xmlNodePtr node, const char *attr_name)
 {
     xmlAttr *attr;
 
     for (attr = node->properties; attr; attr = attr->next)
         if (g_strcmp0 (attr_name, (char *)attr->name) == 0)
-            return attr->children->content;
+            return (const char *)attr->children->content;
 
     return NULL;
 }
 
-G_GNUC_INTERNAL const char *
-gvir_config_xml_get_attribute_content_glib(xmlNodePtr node, const char *attr_name)
-{
-    const xmlChar *attr;
-
-    attr = gvir_config_xml_get_attribute_content(node, attr_name);
-
-    return (const char *) attr;
-}
-
 const char *gvir_config_genum_get_nick (GType enum_type, gint value)
 {
     GEnumClass *enum_class;
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c
index d99a0a2..9a142c9 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -284,7 +284,7 @@ gvir_config_object_get_node_content(GVirConfigObject *object,
     if (node == NULL)
         return NULL;
 
-    return gvir_config_xml_get_child_element_content_glib(node, node_name);
+    return gvir_config_xml_get_child_element_content(node, node_name);
 }
 
 G_GNUC_INTERNAL const char *
@@ -306,7 +306,7 @@ gvir_config_object_get_attribute(GVirConfigObject *object,
             return NULL;
     }
 
-    return gvir_config_xml_get_attribute_content_glib(node, attr_name);
+    return gvir_config_xml_get_attribute_content(node, attr_name);
 }
 
 static xmlNodePtr
@@ -559,7 +559,7 @@ gvir_config_object_get_node_content_uint64(GVirConfigObject *object,
                                            const char *node_name)
 {
     xmlNodePtr node;
-    const xmlChar *str;
+    const char *str;
     guint64 value;
 
     node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(object));
@@ -570,7 +570,7 @@ gvir_config_object_get_node_content_uint64(GVirConfigObject *object,
     if (!str)
         return 0;
 
-    value = g_ascii_strtoull((char *)str, NULL, 0);
+    value = g_ascii_strtoull(str, NULL, 0);
 
     return value;
 }
@@ -582,7 +582,7 @@ gvir_config_object_get_node_content_genum(GVirConfigObject *object,
                                           gint default_value)
 {
     xmlNodePtr node;
-    const xmlChar *str;
+    const char *str;
     gint value;
 
     node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(object));
@@ -593,7 +593,7 @@ gvir_config_object_get_node_content_genum(GVirConfigObject *object,
     if (!str)
         return default_value;
 
-    value = gvir_config_genum_get_value(enum_type, (char *)str, default_value);
+    value = gvir_config_genum_get_value(enum_type, str, default_value);
 
     return value;
 }
@@ -606,7 +606,7 @@ gvir_config_object_get_attribute_genum(GVirConfigObject *object,
                                        gint default_value)
 {
     xmlNodePtr node;
-    const xmlChar *attr_val;
+    const char *attr_val;
     gint value;
 
     g_return_val_if_fail(attr_name != NULL, default_value);
@@ -625,7 +625,7 @@ gvir_config_object_get_attribute_genum(GVirConfigObject *object,
     if (attr_val == NULL)
         return default_value;
 
-    value = gvir_config_genum_get_value(enum_type, (char *)attr_val,
+    value = gvir_config_genum_get_value(enum_type, attr_val,
                                         default_value);
 
     return value;
-- 
1.7.7.6

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]