[gbrainy] Performance enhancement at startup



commit f8cd3255ad5c6ce12d9be94baa0f3cefa30e036a
Author: Jordi Mas <jmas softcatala org>
Date:   Thu Sep 10 16:17:41 2009 +0200

    Performance enhancement at startup

 src/PlayerHistory.cs |   23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)
---
diff --git a/src/PlayerHistory.cs b/src/PlayerHistory.cs
index 0448cdd..92f8ebc 100644
--- a/src/PlayerHistory.cs
+++ b/src/PlayerHistory.cs
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Jordi Mas i Hernàndez <jmas softcatala org>
+ * Copyright (C) 2008-2009 Jordi Mas i Hernàndez <jmas softcatala org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -41,15 +41,21 @@ public class PlayerHistory
 
 	public PlayerHistory ()
 	{
-		games = new List <GameHistory> ();
 		config_path = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
 		config_path = Path.Combine (config_path, "gbrainy");
 		file = Path.Combine (config_path, "PlayerHistory.xml");
-		Load ();
 	}
 
 	public List <GameHistory> Games {
-		get { return games; }
+		get {
+			if (games == null)
+			{
+				Load ();
+				if (games == null) 
+					games = new List <GameHistory> ();
+			}
+			return games; 
+		}
 	}
 
 	public void Clean ()
@@ -72,10 +78,10 @@ public class PlayerHistory
 		history.memory_score = session.MemoryScore;
 		history.total_score = session.TotalScore;
 
-		if (games.Count >= gbrainy.preferences.GetIntValue (Preferences.MaxStoredGamesKey))
-			games.RemoveAt (0);
+		if (Games.Count >= gbrainy.preferences.GetIntValue (Preferences.MaxStoredGamesKey))
+			Games.RemoveAt (0);
 
-		games.Add (history);
+		Games.Add (history);
 		Save ();
 	}
 
@@ -89,7 +95,7 @@ public class PlayerHistory
 			using (FileStream str = File.Create (file))
 			{
 				XmlSerializer bf = new XmlSerializer (typeof (List <GameHistory>));
-				bf.Serialize (str, games);
+				bf.Serialize (str, Games);
 			}
 		}
 		
@@ -114,4 +120,3 @@ public class PlayerHistory
 	
 }
 
-



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]