Browse Source

Merge pull request #30657 from hadrien-psydk/optimize_dir_access_unix_get_next

Optimize DirAccessUnix::get_next() for some file systems
Rémi Verschelde 6 năm trước cách đây
mục cha
commit
fa4cb80a1e
1 tập tin đã thay đổi với 14 bổ sung10 xóa
  1. 14 10
      drivers/unix/dir_access_unix.cpp

+ 14 - 10
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("."));