[gnome-mahjongg] src/game-view.vala: Save one load of the rsvg theme file per draw



commit 45c7a1e40e1fa65492030d689a4ba97f8b2f9710
Author: Alberto Ruiz <aruiz gnome org>
Date:   Sun Apr 19 02:22:24 2020 +0200

    src/game-view.vala: Save one load of the rsvg theme file per draw

 src/game-view.vala | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
---
diff --git a/src/game-view.vala b/src/game-view.vala
index 2024525..5d384de 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -40,7 +40,17 @@ public class GameView : Gtk.DrawingArea
     public string? theme
     {
         get { return _theme; }
-        set { _theme = value; tile_pattern = null; theme_handle = null; queue_draw (); }
+        set {
+            _theme = value;
+            try {
+                theme_handle = new Rsvg.Handle.from_file (value);
+            } catch (Error e) {
+                theme_handle = null;
+            }
+            tile_pattern = null;
+            theme_handle = null;
+            queue_draw ();
+        }
     }
 
     public GameView ()
@@ -209,15 +219,11 @@ public class GameView : Gtk.DrawingArea
 
     private bool get_theme_dimensions (out int width, out int height)
     {
-        try
-        {
-            var svg = new Rsvg.Handle.from_file (theme);
-            width = svg.width;
-            height = svg.height;
+        if (theme_handle != null) {
+            width = theme_handle.width;
+            height = theme_handle.height;
             return true;
-        }
-        catch (Error e)
-        {
+        } else {
             Gdk.Pixbuf.get_file_info (theme, out width, out height);
             return true;
         }


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