[gnome-shell] Speed up initialization of DocInfo objects



commit f215935d2dc115c848882c7805f82832a1a269ea
Author: Siegfried-Angel Gevatter Pujals <rainct ubuntu com>
Date:   Mon Jun 22 14:23:52 2009 +0200

    Speed up initialization of DocInfo objects
    
    We achieve this with two changes:
    
     - Move the Shell.get_thumbnail call in DocInfo from _init
       to getIcon, so that it isn't executed until it's actually
       needed.
       (If caching the output of said call permanently is desired
       we could still do it on the first getIcon invocation, but
       I don't believe this is necessary given that looking up an
       already generated icon is pretty fast and this also gives
       us an updated icon in case the file changes.)
    
     - More importantly, we ommit the get_thumbnail call in case
       the URI doesn't start with file://. Looking up, for example,
       an http:// URI is very slow, and doesn't give us an icon anyway.
    
    http://bugzilla.gnome.org/show_bug.cgi?id=586539

 js/misc/docInfo.js |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/js/misc/docInfo.js b/js/misc/docInfo.js
index dfae4a7..8ac02f6 100644
--- a/js/misc/docInfo.js
+++ b/js/misc/docInfo.js
@@ -19,14 +19,16 @@ DocInfo.prototype = {
         this.name = recentInfo.get_display_name();
         this.uri = recentInfo.get_uri();
         this.mimeType = recentInfo.get_mime_type();
-
-        this._iconPixbuf = Shell.get_thumbnail(this.uri, this.mimeType);
     },
 
     getIcon : function(size) {
         let icon = new Clutter.Texture();
+        let iconPixbuf;
+
+        if (this.uri.match("^file://"))
+            iconPixbuf = Shell.get_thumbnail(this.uri, this.mimeType);
 
-        if (this._iconPixbuf) {
+        if (iconPixbuf) {
             // We calculate the width and height of the texture so as
             // to preserve the aspect ratio of the thumbnail. Because
             // the images generated based on thumbnails don't have an
@@ -34,10 +36,10 @@ DocInfo.prototype = {
             // slightly smaller texture and then create a group around
             // it for padding purposes
 
-            let scalingFactor = (size - THUMBNAIL_ICON_MARGIN * 2) / Math.max(this._iconPixbuf.get_width(), this._iconPixbuf.get_height());
-            icon.set_width(Math.ceil(this._iconPixbuf.get_width() * scalingFactor));
-            icon.set_height(Math.ceil(this._iconPixbuf.get_height() * scalingFactor));
-            Shell.clutter_texture_set_from_pixbuf(icon, this._iconPixbuf);
+            let scalingFactor = (size - THUMBNAIL_ICON_MARGIN * 2) / Math.max(iconPixbuf.get_width(), iconPixbuf.get_height());
+            icon.set_width(Math.ceil(iconPixbuf.get_width() * scalingFactor));
+            icon.set_height(Math.ceil(iconPixbuf.get_height() * scalingFactor));
+            Shell.clutter_texture_set_from_pixbuf(icon, iconPixbuf);
 
             let group = new Clutter.Group({ width: size,
                                             height: size });



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