-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hi list,

what? A mail which is *not* from the bug tracker? Wow. Haven't seen anything
like that in a while. (Sorry for the "bugspam", guys :) )

The attached patch let's imlib cache images again when they are loaded from
disk. E.g. look at the following strace -e file output (strace only displays
file related calls which is why you don't see the actual read()):

stat("../themes/sky/layouts/magnifier.png", {st_mode=S_IFREG|0644, ...}) = 0
stat("../themes/sky/layouts/magnifier.png", {st_mode=S_IFREG|0644, ...}) = 0
stat("../themes/sky/layouts/magnifier.png", {st_mode=S_IFREG|0644, ...}) = 0
open("../themes/sky/layouts/magnifier.png", O_RDONLY) = 8
open("../themes/sky/layouts/magnifier.png", O_RDONLY) = 8
stat("../themes/sky/layouts/floating.png", {st_mode=S_IFREG|0644, ...}) = 0
stat("../themes/sky/layouts/floating.png", {st_mode=S_IFREG|0644, ...}) = 0
stat("../themes/sky/layouts/floating.png", {st_mode=S_IFREG|0644, ...}) = 0
open("../themes/sky/layouts/floating.png", O_RDONLY) = 8
open("../themes/sky/layouts/floating.png", O_RDONLY) = 8
stat("../themes/sky/layouts/magnifier.png", {st_mode=S_IFREG|0644, ...}) = 0
stat("../themes/sky/layouts/magnifier.png", {st_mode=S_IFREG|0644, ...}) = 0
stat("../themes/sky/layouts/magnifier.png", {st_mode=S_IFREG|0644, ...}) = 0
open("../themes/sky/layouts/magnifier.png", O_RDONLY) = 8
open("../themes/sky/layouts/magnifier.png", O_RDONLY) = 8

I switch the layout back and forth and each time the layout is loaded again from
disk.

Now something similar after this patch:

open("../themes/sky/layouts/tile.png", O_RDONLY) = 8
open("../themes/sky/layouts/tile.png", O_RDONLY) = 8
stat("../themes/sky/layouts/floating.png", {st_mode=S_IFREG|0644, ...}) = 0
stat("../themes/sky/layouts/floating.png", {st_mode=S_IFREG|0644, ...}) = 0
stat("../themes/sky/layouts/tile.png", {st_mode=S_IFREG|0644, ...}) = 0
stat("../themes/sky/layouts/tile.png", {st_mode=S_IFREG|0644, ...}) = 0
stat("../themes/sky/layouts/floating.png", {st_mode=S_IFREG|0644, ...}) = 0
stat("../themes/sky/layouts/floating.png", {st_mode=S_IFREG|0644, ...}) = 0
stat("../themes/sky/layouts/tile.png", {st_mode=S_IFREG|0644, ...}) = 0
stat("../themes/sky/layouts/tile.png", {st_mode=S_IFREG|0644, ...}) = 0

The image is now loaded from the cache after imlib checked if the file's times
changed (I looked at the source, it uses ctime and mtime and uses the more
recent one of the two).

Since it's only two stat() calls I don't think this hurts much. (It's definitely
better than just loading the image each time it's referenced)

Cheers,
Uli
- --
"Do you know that books smell like nutmeg or some spice from a foreign land?"
                                                  -- Faber in Fahrenheit 451
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQEcBAEBCAAGBQJLJRzrAAoJECLkKOvLj8sGi60H/RZG8LHT1kEJt1ZooTROTWcg
rs00BNh4Ss+BtTY07JYPfjh0BHE6xmv8HAbETo7gT1hlvYp/w/Kx/CJGRhd9b8nB
8fFs3xc3r1ESIAwKZSU3P5tZdQiaAoMic8cz24xtDz1yb0yGwJaDZjrELZn1x1Cc
o+0Urbge44YpORuEeMk1ROWvIlv/Lke0lqy0ZegnVD4yK7adJKxgl78ir9coyJEs
hbXx4/IqnqwUcXLItnAgUkrR1VKpAMrjm9CtnE8KLL6jP2rNKIYga/fibGkQT+gx
ajZQW1eV+zCgHq4QpCp/jS9ewwh7pl4KvVPL3AIxQJmXtFxKsNheGWPP1ouXGCg=
=sgeF
-----END PGP SIGNATURE-----
>From c4f7fba3d0d5254c386d62895942e1cace90d14f Mon Sep 17 00:00:00 2001
From: Uli Schlachter <[email protected]>
Date: Sat, 12 Dec 2009 13:50:40 +0100
Subject: [PATCH] image: Use imlib2's image cache

This makes imlib add images loaded from files to its image cache again. That way
we avoid loading the same image again and again (e.g. if you cycle through the
list layouts all the layout icons are loaded).

To not reintroduce FS#651 (fixed in 2dadce9b), we call
imlib_image_set_changes_on_disk(). This causes two stat() calls if the same file
is loaded again to check if the file's timestamps changed which is still less
expensive than loading the whole image again.

Signed-off-by: Uli Schlachter <[email protected]>
---
 objects/image.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/objects/image.c b/objects/image.c
index 6548554..0cc9950 100644
--- a/objects/image.c
+++ b/objects/image.c
@@ -285,12 +285,18 @@ image_new_from_file(lua_State *L, const char *filename)
     if(!filename)
         return 0;
 
-    if(!(imimage = imlib_load_image_without_cache(filename)))
+    if(!(imimage = imlib_load_image(filename)))
     {
         warn("cannot load image %s", filename);
         return 0;
     }
 
+    /* Make imlib check if the file changed on disk if it's later opened by the
+     * same file name again before using its cache.
+     */
+    imlib_context_set_image(imimage);
+    imlib_image_set_changes_on_disk();
+
     image = image_new(L);
     image->image = imimage;
 
-- 
1.6.5

Reply via email to