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

SVN revision: 70931
devs/devilhorns/wayland_egl
Cedric BAIL 11 years ago
parent 061c37176d
commit 4fe47342e7
  1. 5
      legacy/efreet/ChangeLog
  2. 9
      legacy/efreet/NEWS
  3. 113
      legacy/efreet/src/lib/efreet_mime.c

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

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

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

Loading…
Cancel
Save