[gbrainy] Minor performance optimizations at startup
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gbrainy] Minor performance optimizations at startup
- Date: Sun, 20 Mar 2011 16:11:56 +0000 (UTC)
commit 5f4f8b8b3fe44d208f4923580406b3ac30d2a101
Author: Jordi Mas <jmas softcatala org>
Date: Sun Mar 20 17:13:13 2011 +0100
Minor performance optimizations at startup
src/Clients/Classical/gbrainy.cs | 16 ++++++++++---
src/Games/Logic/PuzzleDice.cs | 36 +++++++++++++++++++------------
src/Games/Logic/PuzzlePredicateLogic.cs | 5 +++-
3 files changed, 38 insertions(+), 19 deletions(-)
---
diff --git a/src/Clients/Classical/gbrainy.cs b/src/Clients/Classical/gbrainy.cs
index e4a69ce..5167c9e 100644
--- a/src/Clients/Classical/gbrainy.cs
+++ b/src/Clients/Classical/gbrainy.cs
@@ -618,8 +618,12 @@ namespace gbrainy.Clients.Classical
return;
const Gtk.Orientation orientation = Gtk.Orientation.Vertical;
- Preferences.SetIntValue (Preferences.ToolbarOrientationKey, (int) orientation);
- Preferences.Save ();
+
+ if ((Gtk.Orientation) Preferences.GetIntValue (Preferences.ToolbarOrientationKey) != orientation)
+ {
+ Preferences.SetIntValue (Preferences.ToolbarOrientationKey, (int) orientation);
+ Preferences.Save ();
+ }
toolbar.Attach (orientation);
}
@@ -629,8 +633,12 @@ namespace gbrainy.Clients.Classical
return;
const Gtk.Orientation orientation = Gtk.Orientation.Horizontal;
- Preferences.SetIntValue (Preferences.ToolbarOrientationKey, (int) Gtk.Orientation.Horizontal);
- Preferences.Save ();
+
+ if ((Gtk.Orientation) Preferences.GetIntValue (Preferences.ToolbarOrientationKey) != orientation)
+ {
+ Preferences.SetIntValue (Preferences.ToolbarOrientationKey, (int) Gtk.Orientation.Horizontal);
+ Preferences.Save ();
+ }
toolbar.Attach (orientation);
}
diff --git a/src/Games/Logic/PuzzleDice.cs b/src/Games/Logic/PuzzleDice.cs
index 9460817..fb33f4a 100644
--- a/src/Games/Logic/PuzzleDice.cs
+++ b/src/Games/Logic/PuzzleDice.cs
@@ -45,24 +45,29 @@ namespace gbrainy.Games.Logic
}
};
- Problem [] problems =
- {
- new Problem (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("What is the probability of getting a '2' or a '6' in a single throw of a fair 6 sided die? Answer using a fraction (e.g.: 1/2)."),
- "1/3",
- ServiceLocator.Instance.GetService <ITranslations> ().GetString ("There are 2 of 6 possibilities."), true),
-
- new Problem (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("What is the probability of not getting a '5' in a single throw of a fair 6 sided die? Answer using a fraction (e.g.: 1/2)."),
- "5/6",
- ServiceLocator.Instance.GetService <ITranslations> ().GetString ("There are 5 of 6 possibilities."), true),
+ Problem [] problems;
- new Problem (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Two fair 6 sided dices are thrown simultaneously. What is the probability of getting two even numbers? Answer using a fraction (e.g.: 1/2)."),
- "9/36",
- ServiceLocator.Instance.GetService <ITranslations> ().GetString ("There are 9 of 36 possibilities of getting two even numbers."), false),
-
- new Problem (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Two fair 6 sided dices are thrown simultaneously. What is the probability of getting two '6'? Answer using a fraction (e.g.: 1/2)."),
- "1/36",
- ServiceLocator.Instance.GetService <ITranslations> ().GetString ("There is 1 of 6 possibilities of getting a '6' on the first die and the same for the second die."), false),
- };
+ void LoadProblems ()
+ {
+ problems = new Problem []
+ {
+ new Problem (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("What is the probability of getting a '2' or a '6' in a single throw of a fair 6 sided die? Answer using a fraction (e.g.: 1/2)."),
+ "1/3",
+ ServiceLocator.Instance.GetService <ITranslations> ().GetString ("There are 2 of 6 possibilities."), true),
+
+ new Problem (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("What is the probability of not getting a '5' in a single throw of a fair 6 sided die? Answer using a fraction (e.g.: 1/2)."),
+ "5/6",
+ ServiceLocator.Instance.GetService <ITranslations> ().GetString ("There are 5 of 6 possibilities."), true),
+
+ new Problem (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Two fair 6 sided dices are thrown simultaneously. What is the probability of getting two even numbers? Answer using a fraction (e.g.: 1/2)."),
+ "9/36",
+ ServiceLocator.Instance.GetService <ITranslations> ().GetString ("There are 9 of 36 possibilities of getting two even numbers."), false),
+
+ new Problem (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Two fair 6 sided dices are thrown simultaneously. What is the probability of getting two '6'? Answer using a fraction (e.g.: 1/2)."),
+ "1/36",
+ ServiceLocator.Instance.GetService <ITranslations> ().GetString ("There is 1 of 6 possibilities of getting a '6' on the first die and the same for the second die."), false),
+ };
+ }
public override string Name {
get {return ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Dice");}
@@ -78,6 +83,9 @@ namespace gbrainy.Games.Logic
protected override void Initialize ()
{
+ if (problems == null)
+ LoadProblems ();
+
problem = random.Next (problems.Length);
Answer.Correct = problems[problem].answer;
}
diff --git a/src/Games/Logic/PuzzlePredicateLogic.cs b/src/Games/Logic/PuzzlePredicateLogic.cs
index cc46dea..17997d9 100644
--- a/src/Games/Logic/PuzzlePredicateLogic.cs
+++ b/src/Games/Logic/PuzzlePredicateLogic.cs
@@ -53,7 +53,7 @@ namespace gbrainy.Games.Logic
Predicate [] predicates;
- public PuzzlePredicateLogic ()
+ void LoadPredicates ()
{
Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption;
predicates = new Predicate []
@@ -145,6 +145,9 @@ namespace gbrainy.Games.Logic
int answers;
int correct_answer;
+ if (predicates == null)
+ LoadPredicates ();
+
question = random.Next (predicates.Length);
correct_answer = predicates [question].answer_index;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]