[rhythmbox] rhythmdb: replace entry-changed GSList of changes with a GValueArray
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] rhythmdb: replace entry-changed GSList of changes with a GValueArray
- Date: Tue, 6 Apr 2010 13:01:13 +0000 (UTC)
commit c8018fe463491690d77e367ac9280048c59d7b42
Author: Jonathan Matthew <jonathan d14n org>
Date: Tue Apr 6 22:53:59 2010 +1000
rhythmdb: replace entry-changed GSList of changes with a GValueArray
This is a bit inefficient - the change structures get copied twice while
preparing them for emission - but the new representation can be accessed
directly from python code. This might slow startup by a tiny amount,
but otherwise won't be noticeable.
The various handlers we attach to entry-changed were all trivial to
convert.
plugins/daap/rb-daap-share.c | 2 +-
plugins/ipod/rb-ipod-source.c | 18 +++++++++---------
rhythmdb/rhythmdb-query-model.c | 11 ++++++-----
rhythmdb/rhythmdb.c | 25 ++++++++++++++++++++-----
shell/rb-shell-player.c | 16 +++++++++-------
sources/rb-podcast-source.c | 11 ++++++-----
6 files changed, 51 insertions(+), 32 deletions(-)
---
diff --git a/plugins/daap/rb-daap-share.c b/plugins/daap/rb-daap-share.c
index 3a9b8a9..810b0c2 100644
--- a/plugins/daap/rb-daap-share.c
+++ b/plugins/daap/rb-daap-share.c
@@ -1534,7 +1534,7 @@ db_entry_deleted_cb (RhythmDB *db,
static void
db_entry_changed_cb (RhythmDB *db,
RhythmDBEntry *entry,
- GSList *changes,
+ GValueArray *changes,
RBDAAPShare *share)
{
if (rhythmdb_entry_get_boolean (entry, RHYTHMDB_PROP_HIDDEN)) {
diff --git a/plugins/ipod/rb-ipod-source.c b/plugins/ipod/rb-ipod-source.c
index 2ffede5..5c2d862 100644
--- a/plugins/ipod/rb-ipod-source.c
+++ b/plugins/ipod/rb-ipod-source.c
@@ -897,10 +897,10 @@ send_offline_plays_notification (RBiPodSource *source)
static void
rb_ipod_source_entry_changed_cb (RhythmDB *db,
RhythmDBEntry *entry,
- GSList *changes,
+ GValueArray *changes,
RBiPodSource *source)
{
- GSList *t;
+ int i;
/* Ignore entries which are not iPod entries */
RhythmDBEntryType entry_type;
@@ -917,18 +917,18 @@ rb_ipod_source_entry_changed_cb (RhythmDB *db,
*/
if (entry_type != ipod_entry_type) {
return;
- };
-
+ }
/* If an interesting property was changed, update it on the iPod */
/* If the iPod database is being saved in a separate thread, this
- * might not be 100% thread-safe, but at worse we'll modify a field
+ * might not be 100% thread-safe, but at worst we'll modify a field
* at the time it's being saved which will get a wrong value, but
- * that's the worse that can happen and that's pretty theoritical,
+ * that's the worst that can happen and that's pretty theoretical,
* I don't think avoiding it is worth the effort.
*/
- for (t = changes; t; t = t->next) {
- RhythmDBEntryChange *change = t->data;
+ for (i = 0; i < changes->n_values; i++) {
+ GValue *v = g_value_array_get_nth (changes, i);
+ RhythmDBEntryChange *change = g_value_get_boxed (v);
switch (change->prop) {
case RHYTHMDB_PROP_RATING: {
Itdb_Track *track;
@@ -986,7 +986,7 @@ rb_ipod_source_entry_changed_cb (RhythmDB *db,
break;
}
default:
- rb_debug ("Ignoring property %d\n", change->prop);
+ rb_debug ("Ignoring property %d", change->prop);
break;
}
}
diff --git a/rhythmdb/rhythmdb-query-model.c b/rhythmdb/rhythmdb-query-model.c
index b9d53fa..4ed3e80 100644
--- a/rhythmdb/rhythmdb-query-model.c
+++ b/rhythmdb/rhythmdb-query-model.c
@@ -82,7 +82,7 @@ static void rhythmdb_query_model_do_insert (RhythmDBQueryModel *model,
static void rhythmdb_query_model_entry_added_cb (RhythmDB *db, RhythmDBEntry *entry,
RhythmDBQueryModel *model);
static void rhythmdb_query_model_entry_changed_cb (RhythmDB *db, RhythmDBEntry *entry,
- GSList *changes, RhythmDBQueryModel *model);
+ GValueArray *changes, RhythmDBQueryModel *model);
static void rhythmdb_query_model_entry_deleted_cb (RhythmDB *db, RhythmDBEntry *entry,
RhythmDBQueryModel *model);
@@ -1017,11 +1017,11 @@ rhythmdb_query_model_entry_added_cb (RhythmDB *db,
static void
rhythmdb_query_model_entry_changed_cb (RhythmDB *db,
RhythmDBEntry *entry,
- GSList *changes,
+ GValueArray *changes,
RhythmDBQueryModel *model)
{
gboolean hidden = FALSE;
- GSList *t;
+ int i;
hidden = (!model->priv->show_hidden && rhythmdb_entry_get_boolean (entry, RHYTHMDB_PROP_HIDDEN));
@@ -1089,8 +1089,9 @@ rhythmdb_query_model_entry_changed_cb (RhythmDB *db,
* unless this is a chained query model, in which
* case we propagate the parent model's signals instead.
*/
- for (t = changes; t; t = t->next) {
- RhythmDBEntryChange *change = t->data;
+ for (i = 0; i < changes->n_values; i++) {
+ GValue *v = g_value_array_get_nth (changes, i);
+ RhythmDBEntryChange *change = g_value_get_boxed (v);
if (model->priv->base_model == NULL) {
g_signal_emit (G_OBJECT (model),
diff --git a/rhythmdb/rhythmdb.c b/rhythmdb/rhythmdb.c
index 6f110cb..74d909c 100644
--- a/rhythmdb/rhythmdb.c
+++ b/rhythmdb/rhythmdb.c
@@ -321,7 +321,7 @@ rhythmdb_class_init (RhythmDBClass *klass)
* RhythmDB::entry-changed:
* @db: the #RhythmDB
* @entry: the changed #RhythmDBEntry
- * @changes: a #GSList of #RhythmDBEntryChanges structures describing the changes
+ * @changes: a #GValueArray of #RhythmDBEntryChange structures describing the changes
*
* Emitted when a database entry is modified. The @changes list
* contains a structure for each entry property that has been modified.
@@ -332,9 +332,9 @@ rhythmdb_class_init (RhythmDBClass *klass)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (RhythmDBClass, entry_changed),
NULL, NULL,
- rb_marshal_VOID__BOXED_POINTER,
+ rb_marshal_VOID__BOXED_BOXED,
G_TYPE_NONE, 2,
- RHYTHMDB_TYPE_ENTRY, G_TYPE_POINTER);
+ RHYTHMDB_TYPE_ENTRY, G_TYPE_VALUE_ARRAY);
/**
* RhythmDB::entry-keyword-added:
@@ -1360,7 +1360,19 @@ rhythmdb_emit_entry_signals_idle (RhythmDB *db)
if (changed_entries != NULL) {
g_hash_table_iter_init (&iter, changed_entries);
while (g_hash_table_iter_next (&iter, (gpointer *)&entry, (gpointer *)&entry_changes)) {
- g_signal_emit (G_OBJECT (db), rhythmdb_signals[ENTRY_CHANGED], 0, entry, entry_changes);
+ GValueArray *emit_changes;
+ GSList *c;
+
+ emit_changes = g_value_array_new (g_slist_length (entry_changes));
+ for (c = entry_changes; c != NULL; c = c->next) {
+ GValue v = {0,};
+ g_value_init (&v, RHYTHMDB_TYPE_ENTRY_CHANGE);
+ g_value_take_boxed (&v, c->data);
+ g_value_array_append (emit_changes, &v);
+ g_value_unset (&v);
+ }
+ g_signal_emit (G_OBJECT (db), rhythmdb_signals[ENTRY_CHANGED], 0, entry, emit_changes);
+ g_value_array_free (emit_changes);
g_hash_table_iter_remove (&iter);
}
}
@@ -1462,10 +1474,13 @@ process_changed_entries_cb (RhythmDBEntry *entry,
{
GSList *existing;
if (db->priv->changed_entries_to_emit == NULL) {
+ /* the value destroy function is just g_slist_free because we
+ * steal the actual change structures to build the value array.
+ */
db->priv->changed_entries_to_emit = g_hash_table_new_full (NULL,
NULL,
(GDestroyNotify) rhythmdb_entry_unref,
- (GDestroyNotify) free_entry_changes);
+ (GDestroyNotify) g_slist_free);
}
/* if the entry is already in the change map from a previous commit, add the
diff --git a/shell/rb-shell-player.c b/shell/rb-shell-player.c
index 799e59f..380d837 100644
--- a/shell/rb-shell-player.c
+++ b/shell/rb-shell-player.c
@@ -136,9 +136,9 @@ static void rb_shell_player_set_playing_source_internal (RBShellPlayer *player,
static void rb_shell_player_sync_with_source (RBShellPlayer *player);
static void rb_shell_player_sync_with_selected_source (RBShellPlayer *player);
static void rb_shell_player_entry_changed_cb (RhythmDB *db,
- RhythmDBEntry *entry,
- GSList *changes,
- RBShellPlayer *player);
+ RhythmDBEntry *entry,
+ GValueArray *changes,
+ RBShellPlayer *player);
static void rb_shell_player_entry_activated_cb (RBEntryView *view,
RhythmDBEntry *entry,
@@ -1732,6 +1732,7 @@ rb_shell_player_set_playing_entry (RBShellPlayer *player,
g_value_init (&val, G_TYPE_STRING);
g_value_set_string (&val, NULL);
rhythmdb_entry_set (player->priv->db, entry, RHYTHMDB_PROP_PLAYBACK_ERROR, &val);
+ rhythmdb_commit (player->priv->db);
g_value_unset (&val);
return TRUE;
@@ -2807,13 +2808,13 @@ rb_shell_player_property_row_activated_cb (RBPropertyView *view,
static void
rb_shell_player_entry_changed_cb (RhythmDB *db,
RhythmDBEntry *entry,
- GSList *changes,
+ GValueArray *changes,
RBShellPlayer *player)
{
- GSList *t;
gboolean synced = FALSE;
const char *location;
RhythmDBEntry *playing_entry;
+ int i;
playing_entry = rb_shell_player_get_playing_entry (player);
@@ -2826,8 +2827,9 @@ rb_shell_player_entry_changed_cb (RhythmDB *db,
}
location = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION);
- for (t = changes; t; t = t->next) {
- RhythmDBEntryChange *change = t->data;
+ for (i = 0; i < changes->n_values; i++) {
+ GValue *v = g_value_array_get_nth (changes, i);
+ RhythmDBEntryChange *change = g_value_get_boxed (v);
/* update UI if the artist, title or album has changed */
switch (change->prop) {
diff --git a/sources/rb-podcast-source.c b/sources/rb-podcast-source.c
index 8bd9cec..9de2a66 100644
--- a/sources/rb-podcast-source.c
+++ b/sources/rb-podcast-source.c
@@ -223,7 +223,7 @@ static void rb_podcast_source_cmd_new_podcast (GtkAction *action,
RBPodcastSource *source);
static void rb_podcast_source_entry_changed_cb (RhythmDB *db,
RhythmDBEntry *entry,
- GSList *changes,
+ GValueArray *changes,
RBPodcastSource *source);
static void rb_podcast_source_pixbuf_clicked_cb (RBCellRendererPixbuf *renderer,
const char *path,
@@ -2076,20 +2076,21 @@ impl_add_uri (RBSource *asource, const char *uri, const char *title, const char
static void
rb_podcast_source_entry_changed_cb (RhythmDB *db,
RhythmDBEntry *entry,
- GSList *changes,
+ GValueArray *changes,
RBPodcastSource *source)
{
RhythmDBEntryType entry_type;
gboolean feed_changed;
- GSList *t;
+ int i;
entry_type = rhythmdb_entry_get_entry_type (entry);
if (entry_type != RHYTHMDB_ENTRY_TYPE_PODCAST_FEED)
return;
feed_changed = FALSE;
- for (t = changes; t; t = t->next) {
- RhythmDBEntryChange *change = t->data;
+ for (i = 0; i < changes->n_values; i++) {
+ GValue *v = g_value_array_get_nth (changes, i);
+ RhythmDBEntryChange *change = g_value_get_boxed (v);
if (change->prop == RHYTHMDB_PROP_PLAYBACK_ERROR) {
feed_changed = TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]