summaryrefslogtreecommitdiff
path: root/legacy/efreet
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2012-05-11 10:54:47 +0000
committerCedric BAIL <cedric.bail@free.fr>2012-05-11 10:54:47 +0000
commit4fe47342e7220623cc2fdfecf1b42b08a424b5dd (patch)
tree4fba13bca31ee10de27285ecd7d3ab348d18f574 /legacy/efreet
parent061c37176d3d5ded28f1c833061568c24321349c (diff)
efreet: useless work of the day, faster loading of mime type.
SVN revision: 70931
Diffstat (limited to 'legacy/efreet')
-rw-r--r--legacy/efreet/ChangeLog5
-rw-r--r--legacy/efreet/NEWS9
-rw-r--r--legacy/efreet/src/lib/efreet_mime.c113
3 files changed, 88 insertions, 39 deletions
diff --git a/legacy/efreet/ChangeLog b/legacy/efreet/ChangeLog
index e585d26309..f7ad95c5bb 100644
--- a/legacy/efreet/ChangeLog
+++ b/legacy/efreet/ChangeLog
@@ -114,3 +114,8 @@
1142012-04-26 Carsten Haitzler (The Rasterman) 1142012-04-26 Carsten Haitzler (The Rasterman)
115 115
116 1.2.0 release 116 1.2.0 release
117
1182012-05-11 Cedric Bail
119
120 * Faster loading of mime type.
121
diff --git a/legacy/efreet/NEWS b/legacy/efreet/NEWS
index d08842d789..5ebcbad4b6 100644
--- a/legacy/efreet/NEWS
+++ b/legacy/efreet/NEWS
@@ -1,3 +1,12 @@
1Efreet 1.3.0
2
3Changes since Efreet 1.2.0:
4---------------------------
5
6Improvements:
7
8 * Faster mime type loading.
9
1Efreet 1.2.0 10Efreet 1.2.0
2 11
3Changes since Efreet 1.1.0: 12Changes since Efreet 1.1.0:
diff --git a/legacy/efreet/src/lib/efreet_mime.c b/legacy/efreet/src/lib/efreet_mime.c
index 94d4614d65..69fa47e152 100644
--- a/legacy/efreet/src/lib/efreet_mime.c
+++ b/legacy/efreet/src/lib/efreet_mime.c
@@ -807,6 +807,23 @@ efreet_mime_glob_remove(const char *glob)
807 return 0; 807 return 0;
808} 808}
809 809
810static inline const char *
811efreet_eat_space(const char *head, const Eina_File_Lines *ln, Eina_Bool not)
812{
813 if (not)
814 {
815 while (!isspace(*head) && (head < ln->line.end))
816 head++;
817 }
818 else
819 {
820 while (isspace(*head) && (head < ln->line.end))
821 head++;
822 }
823
824 return head;
825}
826
810/** 827/**
811 * @internal 828 * @internal
812 * @param file mime.types file to load 829 * @param file mime.types file to load
@@ -820,45 +837,63 @@ efreet_mime_glob_remove(const char *glob)
820static void 837static void
821efreet_mime_mime_types_load(const char *file) 838efreet_mime_mime_types_load(const char *file)
822{ 839{
823 FILE *f = NULL; 840 const Eina_File_Lines *ln;
824 char buf[4096], mimetype[4096]; 841 Eina_Iterator *it;
825 char ext[4096], *p = NULL, *pp = NULL; 842 Eina_File *f;
826 843 const char *head_line;
827 f = fopen(file, "rb"); 844 const char *word_start;
828 if (!f) return; 845 const char *mimetype;
829 while (fgets(buf, sizeof(buf), f)) 846
830 { 847 f = eina_file_open(file, 0);
831 p = buf; 848 if (!f) return ;
832 while (isspace(*p) && (*p != 0) && (*p != '\n')) p++; 849
833 850 it = eina_file_map_lines(f);
834 if (*p == '#') continue; 851 if (it)
835 if ((*p == '\n') || (*p == 0)) continue; 852 {
836 853 Eina_Strbuf *ext;
837 pp = p; 854
838 while (!isspace(*p) && (*p != 0) && (*p != '\n')) p++; 855 ext = eina_strbuf_new();
839 856
840 if ((*p == '\n') || (*p == 0)) continue; 857 EINA_ITERATOR_FOREACH(it, ln)
841 strncpy(mimetype, pp, (p - pp)); 858 {
842 mimetype[p - pp] = 0; 859 head_line = efreet_eat_space(ln->line.start, ln, EINA_FALSE);
843 860 if (head_line == ln->line.end) continue ;
844 do 861
845 { 862 if (*head_line == '#') continue ;
846 while (isspace(*p) && (*p != 0) && (*p != '\n')) p++; 863
847 864 word_start = head_line;
848 if ((*p == '\n') || (*p == 0)) break; 865 head_line = efreet_eat_space(head_line, ln, EINA_TRUE);
849 866
850 pp = p; 867 if (head_line == ln->line.end) continue ;
851 while (!isspace(*p) && (*p != 0) && (*p != '\n')) p++; 868 mimetype = eina_stringshare_add_length(word_start, head_line - word_start);
852 869 do
853 strncpy(ext, pp, (p - pp)); 870 {
854 ext[p - pp] = 0; 871 head_line = efreet_eat_space(head_line, ln, EINA_FALSE);
855 872 if (head_line == ln->line.end) break ;
856 eina_hash_del(wild, ext, NULL); 873
857 eina_hash_add(wild, ext, (void*)eina_stringshare_add(mimetype)); 874 word_start = head_line;
858 } 875 head_line = efreet_eat_space(head_line, ln, EINA_TRUE);
859 while ((*p != '\n') && (*p != 0)); 876
860 } 877 eina_strbuf_append_length(ext, word_start, head_line - word_start);
861 fclose(f); 878
879 eina_hash_del(wild,
880 eina_strbuf_string_get(ext),
881 NULL);
882 eina_hash_add(wild,
883 eina_strbuf_string_get(ext),
884 eina_stringshare_ref(mimetype));
885
886 eina_strbuf_reset(ext);
887 }
888 while (head_line < ln->line.end);
889
890 eina_stringshare_del(mimetype);
891 }
892
893 eina_strbuf_free(ext);
894 eina_iterator_free(it);
895 }
896 eina_file_close(f);
862} 897}
863 898
864/** 899/**