-
Notifications
You must be signed in to change notification settings - Fork 12.9k
sys: Use readdir withFileTypes option to skip lots of stat syscalls #35286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1353,23 +1353,32 @@ namespace ts { | |
function getAccessibleFileSystemEntries(path: string): FileSystemEntries { | ||
perfLogger.logEvent("ReadDir: " + (path || ".")); | ||
try { | ||
const entries = _fs.readdirSync(path || ".").sort(); | ||
const entries = _fs.readdirSync(path || ".", { withFileTypes: true }); | ||
const files: string[] = []; | ||
const directories: string[] = []; | ||
for (const entry of entries) { | ||
for (const dirent of entries) { | ||
// withFileTypes is not supported before Node 10.10. | ||
const entry = typeof dirent === "string" ? dirent : dirent.name; | ||
|
||
// This is necessary because on some file system node fails to exclude | ||
// "." and "..". See https://github.com/nodejs/node/issues/4002 | ||
if (entry === "." || entry === "..") { | ||
continue; | ||
} | ||
const name = combinePaths(path, entry); | ||
|
||
let stat: any; | ||
try { | ||
stat = _fs.statSync(name); | ||
if (typeof dirent === "string" || dirent.isSymbolicLink()) { | ||
const name = combinePaths(path, entry); | ||
|
||
try { | ||
stat = _fs.statSync(name); | ||
} | ||
catch (e) { | ||
continue; | ||
} | ||
} | ||
catch (e) { | ||
continue; | ||
else { | ||
stat = dirent; | ||
} | ||
|
||
if (stat.isFile()) { | ||
|
@@ -1379,6 +1388,8 @@ namespace ts { | |
directories.push(entry); | ||
} | ||
} | ||
files.sort(); | ||
directories.sort(); | ||
return { files, directories }; | ||
} | ||
catch (e) { | ||
|
@@ -1413,8 +1424,7 @@ namespace ts { | |
} | ||
|
||
function getDirectories(path: string): string[] { | ||
perfLogger.logEvent("ReadDir: " + path); | ||
return filter<string>(_fs.readdirSync(path), dir => fileSystemEntryExists(combinePaths(path, dir), FileSystemEntryKind.Directory)); | ||
return getAccessibleFileSystemEntries(path).directories.slice(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to slice since getAccessibleFileSystemEntries returns new array for directories.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not always: Edit: I’ve now removed that commit again because we didn’t want to change the type of |
||
} | ||
|
||
function realpath(path: string): string { | ||
|
Uh oh!
There was an error while loading. Please reload this page.