efreet: useless work of the day, faster loading of mime type.

SVN revision: 70931
This commit is contained in:
Cedric BAIL 2012-05-11 10:54:47 +00:00
parent 061c37176d
commit 4fe47342e7
3 changed files with 79 additions and 30 deletions

View File

@ -114,3 +114,8 @@
2012-04-26 Carsten Haitzler (The Rasterman) 2012-04-26 Carsten Haitzler (The Rasterman)
1.2.0 release 1.2.0 release
2012-05-11 Cedric Bail
* Faster loading of mime type.

View File

@ -1,3 +1,12 @@
Efreet 1.3.0
Changes since Efreet 1.2.0:
---------------------------
Improvements:
* Faster mime type loading.
Efreet 1.2.0 Efreet 1.2.0
Changes since Efreet 1.1.0: Changes since Efreet 1.1.0:

View File

@ -807,6 +807,23 @@ efreet_mime_glob_remove(const char *glob)
return 0; return 0;
} }
static inline const char *
efreet_eat_space(const char *head, const Eina_File_Lines *ln, Eina_Bool not)
{
if (not)
{
while (!isspace(*head) && (head < ln->line.end))
head++;
}
else
{
while (isspace(*head) && (head < ln->line.end))
head++;
}
return head;
}
/** /**
* @internal * @internal
* @param file mime.types file to load * @param file mime.types file to load
@ -820,45 +837,63 @@ efreet_mime_glob_remove(const char *glob)
static void static void
efreet_mime_mime_types_load(const char *file) efreet_mime_mime_types_load(const char *file)
{ {
FILE *f = NULL; const Eina_File_Lines *ln;
char buf[4096], mimetype[4096]; Eina_Iterator *it;
char ext[4096], *p = NULL, *pp = NULL; Eina_File *f;
const char *head_line;
const char *word_start;
const char *mimetype;
f = fopen(file, "rb"); f = eina_file_open(file, 0);
if (!f) return; if (!f) return ;
while (fgets(buf, sizeof(buf), f))
{
p = buf;
while (isspace(*p) && (*p != 0) && (*p != '\n')) p++;
if (*p == '#') continue; it = eina_file_map_lines(f);
if ((*p == '\n') || (*p == 0)) continue; if (it)
{
Eina_Strbuf *ext;
pp = p; ext = eina_strbuf_new();
while (!isspace(*p) && (*p != 0) && (*p != '\n')) p++;
if ((*p == '\n') || (*p == 0)) continue; EINA_ITERATOR_FOREACH(it, ln)
strncpy(mimetype, pp, (p - pp)); {
mimetype[p - pp] = 0; head_line = efreet_eat_space(ln->line.start, ln, EINA_FALSE);
if (head_line == ln->line.end) continue ;
do if (*head_line == '#') continue ;
{
while (isspace(*p) && (*p != 0) && (*p != '\n')) p++;
if ((*p == '\n') || (*p == 0)) break; word_start = head_line;
head_line = efreet_eat_space(head_line, ln, EINA_TRUE);
pp = p; if (head_line == ln->line.end) continue ;
while (!isspace(*p) && (*p != 0) && (*p != '\n')) p++; mimetype = eina_stringshare_add_length(word_start, head_line - word_start);
do
{
head_line = efreet_eat_space(head_line, ln, EINA_FALSE);
if (head_line == ln->line.end) break ;
strncpy(ext, pp, (p - pp)); word_start = head_line;
ext[p - pp] = 0; head_line = efreet_eat_space(head_line, ln, EINA_TRUE);
eina_hash_del(wild, ext, NULL); eina_strbuf_append_length(ext, word_start, head_line - word_start);
eina_hash_add(wild, ext, (void*)eina_stringshare_add(mimetype));
} eina_hash_del(wild,
while ((*p != '\n') && (*p != 0)); eina_strbuf_string_get(ext),
} NULL);
fclose(f); eina_hash_add(wild,
eina_strbuf_string_get(ext),
eina_stringshare_ref(mimetype));
eina_strbuf_reset(ext);
}
while (head_line < ln->line.end);
eina_stringshare_del(mimetype);
}
eina_strbuf_free(ext);
eina_iterator_free(it);
}
eina_file_close(f);
} }
/** /**