From a9a075279181a71ab3fd165fc34807f66a9f8e62 Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Tue, 3 Mar 2009 07:20:21 +0000 Subject: [PATCH] efreet mime types icon cache. This cache is very simple and should work fine when system does not change, it keeps a direct association of mime-types and found icons, remembering theme and icon size. Search is very fast since it uses stringshared strings and thus direct pointer comparison in hash search. We could optimize it even more if we assumed stringshared strings to come in, so no need to eina_stringshare_add() (which is a hash per se), using just eina_stringshare_ref(). Cache population is limited to compile-time value and just values older than a given threshold are deleted. I do not keep a LRU explicit list, so you might have some old but unused items always alive. I don't find this too bad, sure it will consume more memory, but will not hurt performance. We can change this to purge all expired items by not checking for number of items to remove, removing all that match. Next I plan to find out a good way to cache and speed up file->mime discovery. I plan to do auto-generated state-machine to match extensions, so you don't need to check the same extension character more than once. Example: Input: bla.edc Extensions: edc edj eps png bmp It would first try to match against 'e', 'p' and 'b'. It will match 'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match 'd' and then check for 'c' or 'j'. This will reduce number of comparisons considerably. As I'm running out of time (4am, not much time left on this month), I could use some help here. SVN revision: 39343 --- src/bin/e_fm.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/bin/e_fm.c b/src/bin/e_fm.c index 4efb62586..cdd159b17 100644 --- a/src/bin/e_fm.c +++ b/src/bin/e_fm.c @@ -402,6 +402,9 @@ static const char *_e_fm2_icon_thumb_str = NULL; static const char *_e_fm2_mime_inode_directory = NULL; static const char *_e_fm2_mime_app_desktop = NULL; +static Ecore_Timer *_e_fm2_mime_flush = NULL; +static Ecore_Timer *_e_fm2_mime_clear = NULL; + /* contains: * _e_volume_edd * _e_storage_edd @@ -532,6 +535,20 @@ _e_fm2_icon_h_get(const E_Fm2_Smart_Data *sd) return sd->config->icon.icon.h; } +static int +_e_fm2_mime_flush_cb(void *data __UNUSED__) +{ + efreet_mime_type_cache_flush(); + return 1; +} + +static int +_e_fm2_mime_clear_cb(void *data __UNUSED__) +{ + efreet_mime_type_cache_clear(); + return 1; +} + /***/ EAPI int @@ -573,6 +590,10 @@ e_fm2_init(void) e_fm2_custom_file_init(); efreet_mime_init(); + /* XXX: move this to a central/global place? */ + _e_fm2_mime_flush = ecore_timer_add(60.0, _e_fm2_mime_flush_cb, NULL); + _e_fm2_mime_clear = ecore_timer_add(600.0, _e_fm2_mime_clear_cb, NULL); + _e_fm2_icon_desktop_str = eina_stringshare_add("DESKTOP"); _e_fm2_icon_thumb_str = eina_stringshare_add("THUMB"); _e_fm2_mime_inode_directory = eina_stringshare_add("inode/directory"); @@ -589,6 +610,11 @@ e_fm2_shutdown(void) _eina_stringshare_replace(&_e_fm2_mime_inode_directory, NULL); _eina_stringshare_replace(&_e_fm2_mime_app_desktop, NULL); + ecore_timer_del(_e_fm2_mime_flush); + _e_fm2_mime_flush = NULL; + ecore_timer_del(_e_fm2_mime_clear); + _e_fm2_mime_clear = NULL; + evas_smart_free(_e_fm2_smart); _e_fm2_smart = NULL; E_FREE(_e_fm2_meta_path);