[gnome-games] database: Return GenericSet<Uid> on list_favorite_games()
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] database: Return GenericSet<Uid> on list_favorite_games()
- Date: Fri, 31 Jul 2020 11:25:46 +0000 (UTC)
commit d7f450904e3736e2d720720f8437b444cb26252d
Author: Neville <nevilleantony98 gmail com>
Date: Thu Jul 23 19:10:27 2020 +0530
database: Return GenericSet<Uid> on list_favorite_games()
Instead of converting and adding strings to Uid one by one, just simply
pass it the GenericSet of uids.
src/collection/favorites-collection.vala | 5 +----
src/database/database.vala | 6 +++---
2 files changed, 4 insertions(+), 7 deletions(-)
---
diff --git a/src/collection/favorites-collection.vala b/src/collection/favorites-collection.vala
index 445cffe05..25a4f95df 100644
--- a/src/collection/favorites-collection.vala
+++ b/src/collection/favorites-collection.vala
@@ -14,8 +14,6 @@ private class Games.FavoritesCollection : Object, Collection {
game_collection.game_removed.connect (on_game_removed);
game_collection.game_replaced.connect (on_game_replaced);
- favorite_game_uids = new GenericSet<Uid> (Uid.hash, Uid.equal);
-
game_model = new GameModel ();
game_model.always_replace = true;
}
@@ -42,8 +40,7 @@ private class Games.FavoritesCollection : Object, Collection {
public void load () {
try {
- foreach (var uid in database.list_favorite_games ())
- favorite_game_uids.add (new Uid (uid));
+ favorite_game_uids = database.list_favorite_games ();
}
catch (Error e) {
critical ("Failed to load favorite game uids: %s", e.message);
diff --git a/src/database/database.vala b/src/database/database.vala
index 583847bc4..236552c6b 100644
--- a/src/database/database.vala
+++ b/src/database/database.vala
@@ -422,12 +422,12 @@ private class Games.Database : Object {
return true;
}
- public string[] list_favorite_games () throws Error {
+ public GenericSet<Uid> list_favorite_games () throws Error {
list_favorite_games_query.reset ();
- string[] games = {};
+ var games = new GenericSet<Uid> (Uid.hash, Uid.equal);
while (list_favorite_games_query.step () == Sqlite.ROW)
- games += list_favorite_games_query.column_text (0);
+ games.add (new Uid (list_favorite_games_query.column_text (0)));
return games;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]