[anjuta/newproject: 31/31] pm: Temporary AnjutaProjectNode object to check bindings
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta/newproject: 31/31] pm: Temporary AnjutaProjectNode object to check bindings
- Date: Mon, 6 Sep 2010 18:44:27 +0000 (UTC)
commit 752247578cb45d7dc6a6cfe375d6811f94f36d4e
Author: Sébastien Granjoux <seb sfo free fr>
Date: Mon Sep 6 20:43:39 2010 +0200
pm: Temporary AnjutaProjectNode object to check bindings
libanjuta/anjuta-project.c | 254 ++++++++++++++++++++++++++++++++++++
libanjuta/anjuta-project.h | 49 +++++++
plugins/am-project/projectparser.c | 123 +++++++++++++++++
3 files changed, 426 insertions(+), 0 deletions(-)
---
diff --git a/libanjuta/anjuta-project.c b/libanjuta/anjuta-project.c
index b98f863..6883302 100644
--- a/libanjuta/anjuta-project.c
+++ b/libanjuta/anjuta-project.c
@@ -910,3 +910,257 @@ anjuta_project_node_is_proxy (AnjutaProjectNode *node)
return NODE_DATA (node)->type & ANJUTA_PROJECT_PROXY ? TRUE : FALSE;
}
+typedef struct {
+ AnjutaProjectNodeData base;
+ gpointer data;
+ guint reference;
+} AnjutaProjectIntrospectionData;
+
+
+/**
+ * anjuta_project_introspection_node_new:
+ *
+ * @type: node type
+ * @file: (allow-none): file
+ * @name: file name
+ * @user_data:
+ *
+ * Returns: (transfer none): A list of #GFile corresponding to
+ * each target of the requested type or %NULL if none exists. Free the returned list
+ * with g_list_free() and the files with g_object_unref().
+ */
+AnjutaProjectNode *
+anjuta_project_introspection_node_new (AnjutaProjectNodeType type, GFile *file, const gchar *name, gpointer user_data)
+{
+ AnjutaProjectIntrospectionData *data;
+ AnjutaProjectNode *node;
+
+ data = g_slice_new0(AnjutaProjectIntrospectionData);
+ data->base.type = type;
+ data->base.properties = NULL;
+ data->base.file = file != NULL ? g_object_ref (file) : NULL;
+ data->base.name = name != NULL ? g_strdup (name) : NULL;
+ data->data = user_data;
+
+ node = g_node_new (data);
+ //g_message ("New node %p data %p", node, data);
+
+ return node;
+}
+
+/**
+ * anjuta_project_introspection_node_new0:
+ *
+ * Blah Blah
+ *
+ * Returns: (transfer none): A list of #GFile corresponding to
+ * each target of the requested type or %NULL if none exists. Free the returned list
+ * with g_list_free() and the files with g_object_unref().
+ */
+AnjutaProjectNode *
+anjuta_project_introspection_node_new0 (void)
+{
+ AnjutaProjectIntrospectionData *data;
+
+ data = g_slice_new0(AnjutaProjectIntrospectionData);
+ data->base.type = 0;
+ data->base.properties = NULL;
+ data->base.file = NULL;
+ data->base.state = 0;
+
+ return g_node_new (data);
+
+}
+
+void
+anjuta_project_introspection_node_free (AnjutaProjectNode *node)
+{
+ AnjutaProjectIntrospectionData *data = (AnjutaProjectIntrospectionData *)node->data;
+
+ //g_message ("Free node %p data %p", node, data);
+ if (data->base.file) g_object_unref (data->base.file);
+ if (data->base.name) g_free (data->base.name);
+
+ g_slice_free (AnjutaProjectIntrospectionData, data);
+
+ g_node_destroy (node);
+}
+
+/**
+ * anjuta_project_introspection_node_get_user_data
+ *
+ * @node: node type
+ *
+ * Returns: A list of #GFile corresponding to
+ * each target of the requested type or %NULL if none exists. Free the returned list
+ * with g_list_free() and the files with g_object_unref().
+ */
+gpointer
+anjuta_project_introspection_node_get_user_data (AnjutaProjectNode *node)
+{
+ AnjutaProjectIntrospectionData *data = (AnjutaProjectIntrospectionData *)node->data;
+
+ return data->data;
+}
+
+/* Implement GObject
+ *---------------------------------------------------------------------------*/
+
+G_DEFINE_TYPE (AnjutaProjectGObjectNode, anjuta_project_gobject_node, G_TYPE_OBJECT);
+
+static void
+anjuta_project_gobject_node_init (AnjutaProjectGObjectNode *node)
+{
+ node->next = NULL;
+ node->prev = NULL;
+ node->parent = NULL;
+ node->children = NULL;
+ node->base.type = 0;
+ node->base.properties = NULL;
+ node->base.file = NULL;
+ node->base.name = NULL;
+ node->data = NULL;
+}
+
+static void
+anjuta_project_gobject_node_dispose (GObject *object)
+{
+ AnjutaProjectGObjectNode *node = ANJUTA_PROJECT_GOBJECT_NODE(object);
+
+ if (node->base.file != NULL) g_object_unref (node->base.file);
+ node->base.file = NULL;
+
+ G_OBJECT_CLASS (anjuta_project_gobject_node_parent_class)->dispose (object);
+}
+
+static void
+anjuta_project_gobject_node_finalize (GObject *object)
+{
+ AnjutaProjectGObjectNode *node = ANJUTA_PROJECT_GOBJECT_NODE(object);
+
+ if (node->base.name != NULL) g_free (node->base.name);
+
+ G_OBJECT_CLASS (anjuta_project_gobject_node_parent_class)->finalize (object);
+}
+
+static void
+anjuta_project_gobject_node_class_init (AnjutaProjectGObjectNodeClass *klass)
+{
+ GObjectClass* object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = anjuta_project_gobject_node_finalize;
+ object_class->dispose = anjuta_project_gobject_node_dispose;
+}
+
+/* Constructor & Destructor
+ *---------------------------------------------------------------------------*/
+
+/**
+ * anjuta_project_gobject_node_new:
+ *
+ * @type: node type
+ * @file: (allow-none): file
+ * @name: file name
+ * @user_data:
+ *
+ * Returns: A list of #GFile corresponding to
+ * each target of the requested type or %NULL if none exists. Free the returned list
+ * with g_list_free() and the files with g_object_unref().
+ */
+AnjutaProjectGObjectNode*
+anjuta_project_gobject_node_new (AnjutaProjectNodeType type, GFile *file, const gchar *name, gpointer user_data)
+{
+ AnjutaProjectGObjectNode* node;
+
+ node = g_object_new (ANJUTA_TYPE_PROJECT_GOBJECT_NODE, NULL);
+ node->base.type = type;
+ if (file != NULL) node->base.file = g_object_ref (file);
+ if (name != NULL) node->base.name = g_strdup (name);
+ node->data = user_data;
+ //g_message ("New gnode %p", node);
+
+ return node;
+}
+
+void
+anjuta_project_gobject_node_free (AnjutaProjectGObjectNode* node)
+{
+ g_message ("Free gnode %p", node);
+ g_object_unref (node);
+}
+
+// (type ANJUTA_TYPE_PROJECT_BOXED_NODE):
+
+/**
+ * anjuta_project_boxed_node_new:
+ *
+ * @type: node type
+ * @file: (allow-none): file
+ * @name: file name
+ * @user_data:
+ *
+ * Returns: (type Anjuta.TYPE_PROJECT_BOXED_NODE): A list of #GFile corresponding to
+ * each target of the requested type or %NULL if none exists. Free the returned list
+ * with g_list_free() and the files with g_object_unref().
+ */
+AnjutaProjectNode *
+anjuta_project_boxed_node_new (AnjutaProjectNodeType type, GFile *file, const gchar *name, gpointer user_data)
+{
+ AnjutaProjectIntrospectionData *data;
+ AnjutaProjectNode *node;
+
+ data = g_slice_new0(AnjutaProjectIntrospectionData);
+ data->base.type = type;
+ data->base.properties = NULL;
+ data->base.file = file != NULL ? g_object_ref (file) : NULL;
+ data->base.name = name != NULL ? g_strdup (name) : NULL;
+ data->data = user_data;
+ data->reference = 1;
+
+ node = g_node_new (data);
+ //g_message ("New node %p data %p", node, data);
+
+ return node;
+}
+
+static gpointer
+anjuta_project_boxed_node_copy (gpointer boxed)
+{
+ AnjutaProjectNode *node = (AnjutaProjectNode *)boxed;
+ AnjutaProjectIntrospectionData *data = (AnjutaProjectIntrospectionData *)node->data;
+
+ data->reference++;
+
+ return boxed;
+}
+
+static void
+anjuta_project_boxed_node_free (gpointer boxed)
+{
+ AnjutaProjectNode *node = (AnjutaProjectNode *)boxed;
+ AnjutaProjectIntrospectionData *data = (AnjutaProjectIntrospectionData *)node->data;
+
+ data->reference--;
+ if (data->reference == 0)
+ {
+ anjuta_project_introspection_node_free (node);
+ }
+}
+
+void
+anjuta_project_boxed_node_register (void)
+{
+ g_boxed_type_register_static ("ANJUTA_TYPE_PROJECT_BOXED_NODE", anjuta_project_boxed_node_copy, anjuta_project_boxed_node_free);
+}
+
+GType
+anjuta_project_boxed_node_get_type (void)
+{
+ static GType type_id = 0;
+
+ if (!type_id)
+ type_id = g_boxed_type_register_static ("ANJUTA_TYPE_PROJECT_BOXED_NODE", anjuta_project_boxed_node_copy, anjuta_project_boxed_node_free);
+
+ return type_id;
+}
+
diff --git a/libanjuta/anjuta-project.h b/libanjuta/anjuta-project.h
index 799331e..5229898 100644
--- a/libanjuta/anjuta-project.h
+++ b/libanjuta/anjuta-project.h
@@ -154,6 +154,19 @@ typedef GNode AnjutaProjectSource;
typedef void (*AnjutaProjectNodeFunc) (AnjutaProjectNode *node, gpointer data);
+/* Temporary function for introspection */
+AnjutaProjectNode * anjuta_project_introspection_node_new (AnjutaProjectNodeType type, GFile *file, const gchar *name, gpointer user_data);
+AnjutaProjectNode * anjuta_project_introspection_node_new0 (void);
+gpointer anjuta_project_introspection_node_get_user_data (AnjutaProjectNode *node);
+void anjuta_project_introspection_node_free (AnjutaProjectNode *node);
+
+void anjuta_project_boxed_node_register (void);
+AnjutaProjectNode *anjuta_project_boxed_node_new (AnjutaProjectNodeType type, GFile *file, const gchar *name, gpointer user_data);
+GType anjuta_project_boxed_node_get_type (void);
+
+#define ANJUTA_TYPE_PROJECT_BOXED_NODE (anjuta_project_boxed_node_get_type ())
+
+
AnjutaProjectProperty *anjuta_project_property_next (AnjutaProjectProperty *list);
AnjutaProjectProperty *anjuta_project_property_override (AnjutaProjectProperty *list, AnjutaProjectProperty *prop);
AnjutaProjectProperty *anjuta_project_property_next_item (AnjutaProjectProperty *item);
@@ -224,6 +237,42 @@ AnjutaProjectNode *anjuta_project_proxy_get_node (AnjutaProjectNode *proxy);
gboolean anjuta_project_node_is_proxy (AnjutaProjectNode *node);
+
+
+#define ANJUTA_TYPE_PROJECT_GOBJECT_NODE (anjuta_project_gobject_node_get_type ())
+#define ANJUTA_PROJECT_GOBJECT_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ANJUTA_TYPE_PROJECT_GOBJECT_NODE, AnjutaProjectGObjectNode))
+#define ANJUTA_PROJECT_GOBJECT_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ANJUTA_TYPE_PROJECT_GOBJECT_NODE, AnjutaProjectGObjectNodeClass))
+#define ANJUTA_IS_PROJECT_GOBJECT_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ANJUTA_TYPE_PROJECT_GOBJECT_NODE))
+#define ANJUTA_IS_PROJECT_GOBJECT_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ANJUTA_TYPE_PROJECT_GOBJECT_NODE))
+#define ANJUTA_PROJECT_GOBJECT_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ANJUTA_TYPE_PROJECT_GOBJECT_NODE, AnjutaProjectGObjectNodeClass))
+
+typedef struct _AnjutaProjectGObjectNodeClass AnjutaProjectGObjectNodeClass;
+typedef struct _AnjutaProjectGObjectNode AnjutaProjectGObjectNode;
+
+struct _AnjutaProjectGObjectNodeClass
+{
+ GObjectClass parent_class;
+};
+
+struct _AnjutaProjectGObjectNode
+{
+ GObject parent_instance;
+
+ GNode *next;
+ GNode *prev;
+ GNode *parent;
+ GNode *children;
+ AnjutaProjectNodeData base;
+ gpointer data;
+};
+
+GType anjuta_project_gobject_node_get_type (void) G_GNUC_CONST;
+
+AnjutaProjectGObjectNode* anjuta_project_gobject_node_new (AnjutaProjectNodeType type, GFile *file, const gchar *name, gpointer user_data);
+void anjuta_project_gobject_node_free (AnjutaProjectGObjectNode* project);
+
+void anjuta_project_node_register_boxed (void);
+
G_END_DECLS
#endif
diff --git a/plugins/am-project/projectparser.c b/plugins/am-project/projectparser.c
index 4c53dd7..b7d5494 100644
--- a/plugins/am-project/projectparser.c
+++ b/plugins/am-project/projectparser.c
@@ -354,6 +354,127 @@ get_project_property (AmpProject *project, AnjutaProjectNode *parent, const gcha
return prop;
}
+
+#define NUM_NODE 1000000
+#define NUM_TRY 4
+
+void benchmark(void)
+{
+ GTimer *timer;
+ AnjutaProjectNode *nodes[NUM_NODE];
+ guint i,j;
+ gdouble all_new[NUM_TRY + 1];
+ gdouble all_free[NUM_TRY + 1];
+ gdouble all_both[NUM_TRY + 1] ;
+
+ timer = g_timer_new ();
+
+ for (j = 0; j < NUM_TRY; j++)
+ {
+ g_timer_start (timer);
+ for (i = 0; i < NUM_NODE; i++)
+ {
+ nodes[i] = anjuta_project_introspection_node_new (ANJUTA_PROJECT_ROOT, NULL, "noname", timer);
+ }
+ g_timer_stop (timer);
+ all_new[j] = g_timer_elapsed (timer, NULL);
+ g_timer_start (timer);
+ for (i = 0; i < NUM_NODE; i++)
+ {
+ anjuta_project_introspection_node_free (nodes[i]);
+ }
+ g_timer_stop (timer);
+ all_free[j] = g_timer_elapsed (timer, NULL);
+ g_timer_start (timer);
+ for (i = 0; i < NUM_NODE; i++)
+ {
+ nodes[0] = anjuta_project_introspection_node_new (ANJUTA_PROJECT_ROOT, NULL, "noname", timer);
+ anjuta_project_introspection_node_free (nodes[0]);
+ }
+ g_timer_stop (timer);
+ all_both[j] = g_timer_elapsed (timer, NULL);
+ }
+ all_new[NUM_TRY] = 0;
+ all_free[NUM_TRY] = 0;
+ all_both[NUM_TRY] = 0;
+
+ printf ("all_new ");
+ for (j = 0; j < NUM_TRY; j++)
+ {
+ printf ("%g ", all_new[j]);
+ all_new[NUM_TRY] += all_new[j];
+ }
+ printf (" %g\n", all_new[NUM_TRY] / NUM_TRY);
+ printf ("all_free ");
+ for (j = 0; j < NUM_TRY; j++)
+ {
+ printf ("%g ", all_free[j]);
+ all_free[NUM_TRY] += all_free[j];
+ }
+ printf (" %g\n", all_free[NUM_TRY] / NUM_TRY);
+ printf ("all_both ");
+ for (j = 0; j < NUM_TRY; j++)
+ {
+ printf ("%g ", all_both[j]);
+ all_both[NUM_TRY] += all_both[j];
+ }
+ printf (" %g\n", all_both[NUM_TRY] / NUM_TRY);
+
+
+ for (j = 0; j < NUM_TRY; j++)
+ {
+ g_timer_start (timer);
+ for (i = 0; i < NUM_NODE; i++)
+ {
+ nodes[i] = anjuta_project_gobject_node_new (ANJUTA_PROJECT_ROOT, NULL, "noname", timer);
+ }
+ g_timer_stop (timer);
+ all_new[j] = g_timer_elapsed (timer, NULL);
+ g_timer_start (timer);
+ for (i = 0; i < NUM_NODE; i++)
+ {
+ anjuta_project_gobject_node_free (nodes[i]);
+ }
+ g_timer_stop (timer);
+ all_free[j] = g_timer_elapsed (timer, NULL);
+ g_timer_start (timer);
+ for (i = 0; i < NUM_NODE; i++)
+ {
+ nodes[0] = anjuta_project_gobject_node_new (ANJUTA_PROJECT_ROOT, NULL, "noname", timer);
+ anjuta_project_gobject_node_free (nodes[0]);
+ }
+ g_timer_stop (timer);
+ all_both[j] = g_timer_elapsed (timer, NULL);
+ }
+ all_new[NUM_TRY] = 0;
+ all_free[NUM_TRY] = 0;
+ all_both[NUM_TRY] = 0;
+
+ printf ("all_new ");
+ for (j = 0; j < NUM_TRY; j++)
+ {
+ printf ("%g ", all_new[j]);
+ all_new[NUM_TRY] += all_new[j];
+ }
+ printf (" %g\n", all_new[NUM_TRY] / NUM_TRY);
+ printf ("all_free ");
+ for (j = 0; j < NUM_TRY; j++)
+ {
+ printf ("%g ", all_free[j]);
+ all_free[NUM_TRY] += all_free[j];
+ }
+ printf (" %g\n", all_free[NUM_TRY] / NUM_TRY);
+ printf ("all_both ");
+ for (j = 0; j < NUM_TRY; j++)
+ {
+ printf ("%g ", all_both[j]);
+ all_both[NUM_TRY] += all_both[j];
+ }
+ printf (" %g\n", all_both[NUM_TRY] / NUM_TRY);
+
+ exit (1);
+}
+
/* Automake parsing function
*---------------------------------------------------------------------------*/
@@ -370,6 +491,8 @@ main(int argc, char *argv[])
/* Initialize program */
g_type_init ();
+
+ benchmark ();
anjuta_debug_init ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]