Move ecore_file_ls from an O(n^2) insertion sort to an O(n log n) heap sort,

since we already have it available. Worked fine on OS X and had dj2 check on
Linux to ensure filesystem ordering wasn't skewing the results. He ran a
couple quick benchmarks on a 10k file directory.

Insertion sort results
23:38 <@dj2> real    0m2.134s
23:38 <@dj2> user    0m1.880s
23:38 <@dj2> sys     0m0.120s

Heap sort results
23:35 <@dj2> real    0m0.223s
23:35 <@dj2> user    0m0.072s
23:35 <@dj2> sys     0m0.052s

23:38 <@dj2> and thats on a 3ghz box, heh


SVN revision: 18410
This commit is contained in:
rbdpngn 2005-11-10 05:44:41 +00:00 committed by rbdpngn
parent ea18787d33
commit a90d675613
1 changed files with 22 additions and 21 deletions

View File

@ -261,9 +261,11 @@ ecore_file_readlink(const char *link)
Ecore_List *
ecore_file_ls(const char *dir)
{
char *f;
DIR *dirp;
struct dirent *dp;
Ecore_List *list;
Ecore_List *list;
Ecore_Sheap *heap;
dirp = opendir(dir);
if (!dirp) return NULL;
@ -275,30 +277,29 @@ ecore_file_ls(const char *dir)
{
if ((strcmp(dp->d_name, ".")) && (strcmp(dp->d_name, "..")))
{
char *file, *f;
/* insertion sort */
ecore_list_goto_first(list);
while ((file = ecore_list_current(list)))
{
if (strcasecmp(file, dp->d_name) > 0)
{
f = strdup(dp->d_name);
ecore_list_insert(list, f);
break;
}
ecore_list_next(list);
}
/* nowhwre to go? just append it */
if (!file)
{
f = strdup(dp->d_name);
ecore_list_insert(list, f);
}
f = strdup(dp->d_name);
ecore_list_append(list, f);
}
}
closedir(dirp);
/*
* Push the data into a heap.
*/
heap = ecore_sheap_new(ECORE_COMPARE_CB(strcasecmp), ecore_list_nodes(list));
while ((f = ecore_list_remove_first(list)))
{
ecore_sheap_insert(heap, f);
}
/*
* Extract in sorted order.
*/
while ((f = ecore_sheap_extract(heap)))
{
ecore_list_append(list, f);
}
ecore_list_goto_first(list);
return list;
}