[tracker] libtracker-data: Avoid unnecessary RDF type URI copies on updates
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] libtracker-data: Avoid unnecessary RDF type URI copies on updates
- Date: Tue, 2 Mar 2010 12:40:22 +0000 (UTC)
commit 8531f89746a3b1856dbdf1bafcee47e7699a0ff0
Author: Jürg Billeter <j bitron ch>
Date: Tue Mar 2 12:41:01 2010 +0100
libtracker-data: Avoid unnecessary RDF type URI copies on updates
This reduces memory usage on updates.
src/libtracker-data/tracker-data-query.c | 11 ++++++++++-
src/libtracker-data/tracker-data-update.c | 18 ++++++++----------
src/tracker-store/tracker-events.c | 21 +++++++++++++--------
3 files changed, 31 insertions(+), 19 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-query.c b/src/libtracker-data/tracker-data-query.c
index 164dcb2..0df31c3 100644
--- a/src/libtracker-data/tracker-data-query.c
+++ b/src/libtracker-data/tracker-data-query.c
@@ -62,7 +62,16 @@ tracker_data_query_rdf_type (gint id)
ret = g_ptr_array_sized_new (20);
while (tracker_db_cursor_iter_next (cursor)) {
- g_ptr_array_add (ret, g_strdup (tracker_db_cursor_get_string (cursor, 0)));
+ const gchar *class_uri;
+ TrackerClass *cl;
+
+ class_uri = tracker_db_cursor_get_string (cursor, 0);
+ cl = tracker_ontologies_get_class_by_uri (class_uri);
+ if (!cl) {
+ g_critical ("Unknown class %s", class_uri);
+ continue;
+ }
+ g_ptr_array_add (ret, cl);
}
g_object_unref (cursor);
}
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index c08be22..ee97980 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -72,7 +72,7 @@ struct _TrackerDataUpdateBufferResource {
GHashTable *predicates;
/* string -> TrackerDataUpdateBufferTable */
GHashTable *tables;
- /* string */
+ /* TrackerClass */
GPtrArray *types;
};
@@ -685,7 +685,6 @@ static void resource_buffer_free (TrackerDataUpdateBufferResource *resource)
g_free (resource->subject);
resource->subject = NULL;
- g_ptr_array_foreach (resource->types, (GFunc) g_free, NULL);
g_ptr_array_free (resource->types, TRUE);
resource->types = NULL;
@@ -805,7 +804,6 @@ cache_create_service_decomposed (TrackerClass *cl,
TrackerClass **super_classes;
GValue gvalue = { 0 };
gint i;
- const gchar *class_uri;
/* also create instance of all super classes */
super_classes = tracker_class_get_super_classes (cl);
@@ -814,16 +812,14 @@ cache_create_service_decomposed (TrackerClass *cl,
super_classes++;
}
- class_uri = tracker_class_get_uri (cl);
-
for (i = 0; i < resource_buffer->types->len; i++) {
- if (strcmp (g_ptr_array_index (resource_buffer->types, i), class_uri) == 0) {
+ if (g_ptr_array_index (resource_buffer->types, i) == cl) {
/* ignore duplicate statement */
return;
}
}
- g_ptr_array_add (resource_buffer->types, g_strdup (class_uri));
+ g_ptr_array_add (resource_buffer->types, cl);
g_value_init (&gvalue, G_TYPE_INT);
@@ -835,6 +831,9 @@ cache_create_service_decomposed (TrackerClass *cl,
tracker_class_set_count (cl, tracker_class_get_count (cl) + 1);
if (insert_callbacks) {
guint n;
+ const gchar *class_uri;
+
+ class_uri = tracker_class_get_uri (cl);
for (n = 0; n < insert_callbacks->len; n++) {
TrackerStatementDelegate *delegate;
@@ -925,8 +924,7 @@ check_property_domain (TrackerProperty *property)
gint type_index;
for (type_index = 0; type_index < resource_buffer->types->len; type_index++) {
- if (strcmp (tracker_class_get_uri (tracker_property_get_domain (property)),
- g_ptr_array_index (resource_buffer->types, type_index)) == 0) {
+ if (tracker_property_get_domain (property) == g_ptr_array_index (resource_buffer->types, type_index)) {
return TRUE;
}
}
@@ -1268,7 +1266,7 @@ cache_delete_resource_type (TrackerClass *class,
found = FALSE;
for (i = 0; i < resource_buffer->types->len; i++) {
- if (strcmp (g_ptr_array_index (resource_buffer->types, i), tracker_class_get_uri (class)) == 0) {
+ if (g_ptr_array_index (resource_buffer->types, i) == class) {
found = TRUE;
}
}
diff --git a/src/tracker-store/tracker-events.c b/src/tracker-store/tracker-events.c
index 4402a6b..4986cbc 100644
--- a/src/tracker-store/tracker-events.c
+++ b/src/tracker-store/tracker-events.c
@@ -38,23 +38,30 @@ static void
tracker_events_add_allow (const gchar *rdf_class)
{
EventsPrivate *private;
+ TrackerClass *cl;
private = g_static_private_get (&private_key);
g_return_if_fail (private != NULL);
- g_hash_table_insert (private->allowances, g_strdup (rdf_class),
+ cl = tracker_ontologies_get_class_by_uri (rdf_class);
+ if (!cl) {
+ g_critical ("Unknown class %s", rdf_class);
+ return;
+ }
+
+ g_hash_table_insert (private->allowances, cl,
GINT_TO_POINTER (TRUE));
}
static gboolean
-is_allowed (EventsPrivate *private, const gchar *rdf_class)
+is_allowed (EventsPrivate *private, TrackerClass *rdf_class)
{
return (g_hash_table_lookup (private->allowances, rdf_class) != NULL) ? TRUE : FALSE;
}
static void
prepare_event_for_rdf_type (EventsPrivate *private,
- const gchar *rdf_class ,
+ TrackerClass *rdf_class ,
const gchar *uri,
TrackerDBusEventsType type,
const gchar *predicate)
@@ -66,7 +73,7 @@ prepare_event_for_rdf_type (EventsPrivate *private,
}
event.type = type;
- event.class = tracker_ontologies_get_class_by_uri (rdf_class);
+ event.class = rdf_class;
event.predicate = tracker_ontologies_get_property_by_uri (predicate);
event.subject = g_strdup (uri);
@@ -101,7 +108,7 @@ tracker_events_insert (const gchar *uri,
} else if (type == TRACKER_DBUS_EVENTS_TYPE_UPDATE) {
/* In this case we had an INSERT for a resource that didn't exist
* yet, but it was not the rdf:type predicate being inserted */
- if (is_allowed (private, (gpointer) TRACKER_RDFS_PREFIX "Resource")) {
+ if (is_allowed (private, tracker_ontologies_get_class_by_uri (TRACKER_RDFS_PREFIX "Resource"))) {
prepare_event_for_rdf_type (private,
(gpointer) TRACKER_RDFS_PREFIX "Resource",
uri, type, predicate);
@@ -171,9 +178,7 @@ tracker_events_init (TrackerNotifyClassGetter callback)
private,
(GDestroyNotify) free_private);
- private->allowances = g_hash_table_new_full (g_str_hash, g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) NULL);
+ private->allowances = g_hash_table_new (g_direct_hash, g_direct_equal);
private->events = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]