[tracker/class-signal] libtracker-data: class-signal: Use bsearch() for sorting instead of linear s
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/class-signal] libtracker-data: class-signal: Use bsearch() for sorting instead of linear s
- Date: Tue, 31 Aug 2010 14:07:51 +0000 (UTC)
commit 2bdfed27de299e44b6c32ef6221e9811d33f67ee
Author: Philip Van Hoof <philip codeminded be>
Date: Tue Aug 31 16:06:17 2010 +0200
libtracker-data: class-signal: Use bsearch() for sorting instead of linear s
src/libtracker-data/tracker-class.c | 29 ++++++++++++++++++++++-------
1 files changed, 22 insertions(+), 7 deletions(-)
---
diff --git a/src/libtracker-data/tracker-class.c b/src/libtracker-data/tracker-class.c
index 05b1f59..44af30e 100644
--- a/src/libtracker-data/tracker-class.c
+++ b/src/libtracker-data/tracker-class.c
@@ -605,6 +605,16 @@ tracker_class_transact_events (TrackerClass *class)
}
+
+
+static int
+comp_gint64(const void *m1, const void *m2)
+{
+ gint64 mi1 = * (gint64 *) m1;
+ gint64 mi2 = * (gint64 *) m2;
+ return mi1 - mi2;
+}
+
static void
insert_vals_into_arrays (GArray *sub_pred_ids,
GArray *obj_graph_ids,
@@ -613,21 +623,26 @@ insert_vals_into_arrays (GArray *sub_pred_ids,
gint pred_id,
gint object_id)
{
- guint i;
gint64 sub_pred_id;
gint64 obj_graph_id;
+ gint64 *val;
sub_pred_id = (gint64) subject_id;
sub_pred_id = sub_pred_id << 32 | pred_id;
obj_graph_id = (gint64) object_id;
obj_graph_id = obj_graph_id << 32 | graph_id;
- for (i = 0; i < sub_pred_ids->len; i++) {
- if (sub_pred_id < g_array_index (sub_pred_ids, gint64, i)) {
- g_array_insert_val (sub_pred_ids, i, sub_pred_id);
- g_array_insert_val (obj_graph_ids, i, obj_graph_id);
- return;
- }
+ val = (gint64*) bsearch(&sub_pred_id,
+ sub_pred_ids->data,
+ sub_pred_ids->len,
+ sizeof(gint64),
+ comp_gint64);
+
+ if (val != NULL) {
+ gint pos = val - (gint64*)sub_pred_ids->data;
+ g_array_insert_val (sub_pred_ids, pos, sub_pred_id);
+ g_array_insert_val (obj_graph_ids, pos, obj_graph_id);
+ return;
}
g_array_append_val (sub_pred_ids, sub_pred_id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]