summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorHadrien <hadrien@psydk.org>2019-07-17 20:34:37 +0200
committerHadrien <hadrien@psydk.org>2019-07-17 20:34:37 +0200
commit1898a559a94d803ba3ead9127deb65c5a61aefaa (patch)
treef7e7d65c0c29f77d631c4ff70b6c85d09acc22c6 /drivers
parentd087a9e3283528792634de84b55a607d9b9b5137 (diff)
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.
Diffstat (limited to 'drivers')
-rw-r--r--drivers/unix/dir_access_unix.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp
index 251bab5783..d5582d00ed 100644
--- a/drivers/unix/dir_access_unix.cpp
+++ b/drivers/unix/dir_access_unix.cpp
@@ -136,27 +136,31 @@ String DirAccessUnix::get_next() {
return "";
}
- //typedef struct stat Stat;
- struct stat flags;
-
String fname = fix_unicode_name(entry->d_name);
- String f = current_dir.plus_file(fname);
+ if (entry->d_type == DT_UNKNOWN) {
+ //typedef struct stat Stat;
+ struct stat flags;
+
+ String f = current_dir.plus_file(fname);
+
+ if (stat(f.utf8().get_data(), &flags) == 0) {
- if (stat(f.utf8().get_data(), &flags) == 0) {
+ if (S_ISDIR(flags.st_mode)) {
- if (S_ISDIR(flags.st_mode)) {
+ _cisdir = true;
- _cisdir = true;
+ } else {
+
+ _cisdir = false;
+ }
} else {
_cisdir = false;
}
-
} else {
-
- _cisdir = false;
+ _cisdir = (entry->d_type == DT_DIR);
}
_cishidden = (fname != "." && fname != ".." && fname.begins_with("."));