Optimize DirAccessUnix::get_next() for some file systems

On some file systems, like ext4 on Linux, readdir() gives enough
information to determine the entry type in order to avoid doing
a stat() system call.

Use this information and call stat() only if necessary.
This commit is contained in:
Hadrien 2019-07-17 20:34:37 +02:00
parent d087a9e328
commit 1898a559a9

View file

@ -136,11 +136,12 @@ String DirAccessUnix::get_next() {
return "";
}
String fname = fix_unicode_name(entry->d_name);
if (entry->d_type == DT_UNKNOWN) {
//typedef struct stat Stat;
struct stat flags;
String fname = fix_unicode_name(entry->d_name);
String f = current_dir.plus_file(fname);
if (stat(f.utf8().get_data(), &flags) == 0) {
@ -158,6 +159,9 @@ String DirAccessUnix::get_next() {
_cisdir = false;
}
} else {
_cisdir = (entry->d_type == DT_DIR);
}
_cishidden = (fname != "." && fname != ".." && fname.begins_with("."));