Improved file loading time

This commit is contained in:
windows-server-2003 2018-09-13 17:47:48 +09:00 committed by d0k3
parent 29b05aee54
commit 9c4ff77476

View File

@ -5,26 +5,25 @@ void DirEntryCpy(DirEntry* dest, const DirEntry* orig) {
dest->name = dest->path + (orig->name - orig->path); dest->name = dest->path + (orig->name - orig->path);
} }
int compDirEntry(const void* e1, const void* e2) {
const DirEntry* entry1 = (const DirEntry*) e1;
const DirEntry* entry2 = (const DirEntry*) e2;
if (entry1->type == T_DOTDOT) return -1;
if (entry2->type == T_DOTDOT) return 1;
if (entry1->type != entry2->type)
return entry1->type - entry2->type;
return strncasecmp(entry1->path, entry2->path, 256);
}
void SortDirStruct(DirStruct* contents) { void SortDirStruct(DirStruct* contents) {
for (u32 s = 0; s < contents->n_entries; s++) { qsort(contents->entry, contents->n_entries, sizeof(DirEntry), compDirEntry);
DirEntry* cmp0 = &(contents->entry[s]); for (int i = 0; i < (int)contents->n_entries; i++) {
DirEntry* min0 = cmp0; DirEntry* entry = &(contents->entry[i]);
if (cmp0->type == T_DOTDOT) continue; if (entry->type == T_DOTDOT) {
for (u32 c = s + 1; c < contents->n_entries; c++) { entry->name = entry->path + 8;
DirEntry* cmp1 = &(contents->entry[c]); } else {
if (min0->type != cmp1->type) { char* slash = strrchr(entry->path, '/');
if (min0->type > cmp1->type) entry->name = slash ? slash + 1 : entry->path;
min0 = cmp1;
continue;
}
if (strncasecmp(min0->name, cmp1->name, 256) > 0)
min0 = cmp1;
}
if (min0 != cmp0) {
DirEntry swap; // swap entries and fix names
DirEntryCpy(&swap, cmp0);
DirEntryCpy(cmp0, min0);
DirEntryCpy(min0, &swap);
} }
} }
} }