[tracker/tracker-0.8] tracker-store: Optimize memory use for class signals
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-0.8] tracker-store: Optimize memory use for class signals
- Date: Thu, 17 Jun 2010 15:37:44 +0000 (UTC)
commit 2436aa5c15a4e885534621577ae109495509a48a
Author: Philip Van Hoof <philip codeminded be>
Date: Thu Jun 10 15:15:42 2010 +0200
tracker-store: Optimize memory use for class signals
src/tracker-store/tracker-resource-class.c | 57 ++++++++++------------------
src/tracker-store/tracker-resource-class.h | 3 +-
src/tracker-store/tracker-resources.c | 2 +-
3 files changed, 23 insertions(+), 39 deletions(-)
---
diff --git a/src/tracker-store/tracker-resource-class.c b/src/tracker-store/tracker-resource-class.c
index 9df66c3..71872dc 100644
--- a/src/tracker-store/tracker-resource-class.c
+++ b/src/tracker-store/tracker-resource-class.c
@@ -45,7 +45,8 @@ typedef struct {
} TrackerResourceClassPrivate;
typedef struct {
- gchar *uri, *predicate;
+ gchar *uri;
+ TrackerProperty *predicate;
} ChangedItem;
enum {
@@ -128,6 +129,7 @@ emit_strings (TrackerResourceClass *object, gint signal_, GPtrArray *array)
strings_to_emit[i] = array->pdata [i];
}
+
g_signal_emit (object, signal_, 0, strings_to_emit);
/* Normal free, not a GStrv free, we free the strings later */
@@ -139,19 +141,19 @@ static void
emit_changed_strings (TrackerResourceClass *object, GPtrArray *array)
{
GStrv stringsa_to_emit;
- GStrv stringsb_to_emit;
+ const gchar **stringsb_to_emit;
guint i;
if (array->len > 0) {
stringsa_to_emit = (GStrv) g_malloc0 (sizeof (gchar *) * (array->len + 1));
- stringsb_to_emit = (GStrv) g_malloc0 (sizeof (gchar *) * (array->len + 1));
+ stringsb_to_emit = g_malloc0 (sizeof (const gchar *) * (array->len + 1));
for (i = 0; i < array->len; i++) {
ChangedItem *item = array->pdata [i];
stringsa_to_emit[i] = item->uri;
- stringsb_to_emit[i] = item->predicate;
+ stringsb_to_emit[i] = tracker_property_get_uri (item->predicate);
}
g_signal_emit (object, signals[SUBJECTS_CHANGED], 0,
@@ -168,7 +170,9 @@ free_changed_array (GPtrArray *array)
{
guint i;
for (i = 0; i < array->len; i++) {
- g_slice_free (ChangedItem, array->pdata [i]);
+ ChangedItem *item = array->pdata [i];
+ g_object_unref (item->predicate);
+ g_slice_free (ChangedItem, item);
}
g_ptr_array_free (array, TRUE);
}
@@ -265,31 +269,10 @@ has_already (GPtrArray *array, const gchar *uri)
return FALSE;
}
-/*
- static gboolean
- changed_has_already (GPtrArray *array, const gchar *uri, const gchar *predicate)
- {
- guint i;
-
- if (!array) {
- return FALSE;
- }
-
- for (i = 0; i < array->len; i++) {
- ChangedItem *item = g_ptr_array_index (array, i);
- if (g_strcmp0 (item->uri, uri) == 0 && g_strcmp0 (item->predicate, predicate) == 0) {
- return TRUE;
- }
- }
-
- return FALSE;
- }
-*/
-
void
tracker_resource_class_add_event (TrackerResourceClass *object,
const gchar *uri,
- const gchar *predicate,
+ TrackerProperty *predicate,
TrackerDBusEventsType type)
{
TrackerResourceClassPrivate *priv;
@@ -310,19 +293,19 @@ tracker_resource_class_add_event (TrackerResourceClass *object,
}
break;
case TRACKER_DBUS_EVENTS_TYPE_UPDATE: {
- /* Duplicate checking slows down too much
- if (!changed_has_already (priv->ups, uri, predicate)) { */
- ChangedItem *item;
+ /* Duplicate checking slows down too much
+ if (!changed_has_already (priv->ups, uri, predicate)) { */
+ ChangedItem *item;
- item = g_slice_new (ChangedItem);
+ item = g_slice_new (ChangedItem);
- item->uri = g_string_chunk_insert_const (priv->changed_strings, uri);
- item->predicate = g_string_chunk_insert_const (priv->changed_strings, predicate);
+ item->uri = g_string_chunk_insert_const (priv->changed_strings, uri);
+ item->predicate = g_object_ref (predicate);
- if (!priv->ups)
- priv->ups = g_ptr_array_new ();
- g_ptr_array_add (priv->ups, item);
- }
+ if (!priv->ups)
+ priv->ups = g_ptr_array_new ();
+ g_ptr_array_add (priv->ups, item);
+ }
break;
case TRACKER_DBUS_EVENTS_TYPE_DELETE:
if (!has_already (priv->dels, uri)) {
diff --git a/src/tracker-store/tracker-resource-class.h b/src/tracker-store/tracker-resource-class.h
index 884cfe0..1092ab0 100644
--- a/src/tracker-store/tracker-resource-class.h
+++ b/src/tracker-store/tracker-resource-class.h
@@ -25,6 +25,7 @@
#include <glib-object.h>
#include <libtracker-common/tracker-dbus.h>
+#include <libtracker-data/tracker-property.h>
#define TRACKER_RESOURCES_CLASS_SERVICE "org.freedesktop.Tracker1"
#define TRACKER_RESOURCES_CLASS_PATH "/org/freedesktop/Tracker1/Resources/Classes/%s"
@@ -56,8 +57,8 @@ TrackerResourceClass *tracker_resource_class_new (const gchar *rdf_cl
const gchar * tracker_resource_class_get_rdf_class (TrackerResourceClass *object);
void tracker_resource_class_add_event (TrackerResourceClass *object,
- const gchar *predicate,
const gchar *uri,
+ TrackerProperty *predicate,
TrackerDBusEventsType type);
void tracker_resource_class_emit_events (TrackerResourceClass *object);
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index 2b964f6..120ac91 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -464,7 +464,7 @@ on_statements_committed (gpointer user_data)
for (l = event_sources; l; l = l->next) {
TrackerResourceClass *class_ = l->data;
if (g_strcmp0 (tracker_class_get_uri (event->class), tracker_resource_class_get_rdf_class (class_)) == 0) {
- tracker_resource_class_add_event (class_, event->subject, tracker_property_get_uri (event->predicate), event->type);
+ tracker_resource_class_add_event (class_, event->subject, event->predicate, event->type);
if (!to_emit) {
to_emit = g_hash_table_new (NULL, NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]